Skip to content

Instantly share code, notes, and snippets.

@akirco
Last active July 25, 2023 12:08
Show Gist options
  • Save akirco/c22f3a0960d0a473e1945755b3e67353 to your computer and use it in GitHub Desktop.
Save akirco/c22f3a0960d0a473e1945755b3e67353 to your computer and use it in GitHub Desktop.
snippets - generate random pwd
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