]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Replace use of std::rand with improved C++11 random
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Sat, 20 May 2023 16:34:54 +0000 (00:34 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 20 Jul 2023 15:32:28 +0000 (23:32 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/sharemodel.cpp

index 45520a4c52b4f55cfe6d11ff8cb14d6134259cfc..963c4d46b4a9b6f99b1b6163c379702c83492784 100644 (file)
@@ -17,6 +17,7 @@
 #include <QFileInfo>
 #include <QTimeZone>
 
+#include <random>
 #include <openssl/rand.h>
 
 #include "account.h"
@@ -54,6 +55,9 @@ QString createRandomPassword()
         { specialChars, specialCharMatch },
     };
 
+    std::random_device rand_dev;
+    std::mt19937 rng(rand_dev());
+
     QString passwd;
     unsigned char unsignedCharArray[numChars];
 
@@ -76,8 +80,11 @@ QString createRandomPassword()
         }
 
         // add random required character at random position
-        const auto passwdInsertIndex = std::rand() % passwd.length();
-        const auto charToInsertIndex = std::rand() % selectionChars.length();
+        std::uniform_int_distribution<std::mt19937::result_type> passwdDist(0, passwd.length() - 1);
+        std::uniform_int_distribution<std::mt19937::result_type> charsDist(0, selectionChars.length() - 1);
+
+        const auto passwdInsertIndex = passwdDist(rng);
+        const auto charToInsertIndex = charsDist(rng);
         const auto charToInsert = selectionChars.at(charToInsertIndex);
 
         passwd.insert(passwdInsertIndex, charToInsert);