Skip to content

Instantly share code, notes, and snippets.

@daanta-real
Created April 27, 2024 13:49
Show Gist options
  • Save daanta-real/bf849aab98e7bfdc028759ac080d9ffb to your computer and use it in GitHub Desktop.
Save daanta-real/bf849aab98e7bfdc028759ac080d9ffb to your computer and use it in GitHub Desktop.
random password generator
function generateRandomPassword(length) {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=[]{}|;:,.<>? ";
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
return password;
}
const randomPassword = generateRandomPassword(100);
console.log(randomPassword);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment