Browse Source

Replace Math.random() with crypto.randomBytes()

pull/3196/head
Thomas Kaul 1 year ago
parent
commit
4f31c40891
  1. 7
      apps/api/src/app/user/user.service.ts

7
apps/api/src/app/user/user.service.ts

@ -452,14 +452,15 @@ export class UserService {
}
private getRandomString(length: number) {
const bytes = crypto.randomBytes(length);
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const result = [];
for (let i = 0; i < length; i++) {
result.push(
characters.charAt(Math.floor(Math.random() * characters.length))
);
const randomByte = bytes[i];
result.push(characters[randomByte % characters.length]);
}
return result.join('');
}
}

Loading…
Cancel
Save