Skip to content

Instantly share code, notes, and snippets.

@askehansen
Created June 2, 2014 10:04
Show Gist options
  • Save askehansen/2cc2d149cde52141c1c2 to your computer and use it in GitHub Desktop.
Save askehansen/2cc2d149cde52141c1c2 to your computer and use it in GitHub Desktop.
Generate random password
function generatePassword(length) {
var charset = "abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
document.activeElement.value = prompt('Password:', generatePassword(16));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment