Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Uvacoder/e5c61b40df1d79b573c59544dbcef615 to your computer and use it in GitHub Desktop.

Select an option

Save Uvacoder/e5c61b40df1d79b573c59544dbcef615 to your computer and use it in GitHub Desktop.
Generate random password
const CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}[]:;<>?/|\\';
function generatePassword(length = 12) {
let pass = '';
for (let i = length; i > 0; --i) pass += CHARS[Math.floor(Math.random() * CHARS.length)];
return pass
}
// Usage:
generatePassword(15)
// > "hBI!A31Hs}(oIv*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment