mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-03 19:27:28 +00:00
use a better random integer generator - fixes #810
This commit is contained in:
parent
1ec5e846c5
commit
2e3eaaddcc
1 changed files with 2 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue