1 export const alphabeticChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
2 export const digits = '0123456789';
3 export const specialChars = '!#$%&()*+.:;<=>?@[]^';
5 export const generatePassword = (options: { useSpecialChars: boolean; length: number }) => {
6 const chars = Array.from(alphabeticChars + digits + (options.useSpecialChars ? specialChars : ''));
7 const randomValues = crypto.getRandomValues(new Uint8Array(options.length));
9 const passwordChars = Array.from(randomValues).map((n) => {
10 const rangeBoundMaxIndex = n % chars.length;
11 return chars[rangeBoundMaxIndex];
14 return passwordChars.join('');