merge: use a better random integer generator - fixes #810 (!779)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/779

Closes #810

Approved-by: Hazelnoot <acomputerdog@gmail.com>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
Marie 2024-11-27 19:19:34 +00:00
commit 436e93540a

View file

@ -14,11 +14,8 @@ export function secureRndstr(length = 32, { chars = LU_CHARS } = {}): string {
let str = '';
for (let i = 0; i < length; i++) {
let rand = Math.floor((crypto.randomBytes(1).readUInt8(0) / 0xFF) * chars_len);
if (rand === chars_len) {
rand = chars_len - 1;
}
str += chars.charAt(rand);
const rand = crypto.randomInt(0, chars_len);
str += chars.charAt(rand);
}
return str;