Last active
July 25, 2023 12:08
-
-
Save akirco/c22f3a0960d0a473e1945755b3e67353 to your computer and use it in GitHub Desktop.
snippets - generate random pwd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generatePassword(length) { | |
let charset = | |
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+={}[]|\\:;\"'<>,.?/"; | |
let password = ""; | |
for (let i = 0; i < length; i++) { | |
let randomIndex = Math.floor(Math.random() * charset.length); | |
password += charset[randomIndex]; | |
} | |
return password; | |
} | |
console.log(generatePassword()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment