Skip to content

Instantly share code, notes, and snippets.

@palpich
Last active April 12, 2022 11:52
Show Gist options
  • Save palpich/8341f4fb0dd9af421bd39ff6870eed4c to your computer and use it in GitHub Desktop.
Save palpich/8341f4fb0dd9af421bd39ff6870eed4c to your computer and use it in GitHub Desktop.
Simple password generate
function generatePassword(length: number) {
const dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
const array = new Uint8Array(length);
self.crypto.getRandomValues(array);
let password = ''
for (var i = 0; i < array.length; i++) {
password += dict.charAt(array[i] % dict.length)
}
return password
}
console.log(generatePassword(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment