Simplify password generation in sharemodel

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-05-20 23:12:31 +08:00
parent c4d1bdf46f
commit 32acf504cb
No known key found for this signature in database
GPG Key ID: C839200C384636B0

View File

@ -37,10 +37,15 @@ QString createRandomPassword()
constexpr auto numChars = 24;
QString passwd;
while(passwd.length() < numChars) {
const auto remainingChars = numChars - passwd.length();
unsigned char unsignedCharArray[remainingChars];
RAND_bytes(unsignedCharArray, remainingChars);
unsigned char unsignedCharArray[numChars];
RAND_bytes(unsignedCharArray, numChars);
for (auto i = 0; i < numChars; i++) {
auto byte = unsignedCharArray[i];
byte %= asciiRange;
byte += asciiMin;
passwd.append(byte);
}
for (auto i = 0; i < remainingChars; i++) {
auto byte = unsignedCharArray[i];