Skip to content

Instantly share code, notes, and snippets.

@nyl2k8
Created July 1, 2019 16:16
Show Gist options
  • Save nyl2k8/602f3b847ac9ec09976773b8be2c05a4 to your computer and use it in GitHub Desktop.
Save nyl2k8/602f3b847ac9ec09976773b8be2c05a4 to your computer and use it in GitHub Desktop.
Javascript Password Generator.
function generatePassword() {
var numCaps = 1;
var numLower = 6;
var numChars = 1;
var stringLength = numCaps + numLower + numChars;
var randomString = '';
var caps = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
var lower = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var chars = ['!','@','€','£','#','$','%','^','&','*','(',')','-','_','+','='];
for(var i=0; i<numCaps; i++){
var rcap = caps[Math.floor(Math.random()*caps.length)]
randomString += rcap;
}
for(var i=0; i<numLower; i++){
var rlow = lower[Math.floor(Math.random()*lower.length)]
randomString += rlow;
}
for(var i=0; i<numChars; i++){
var rchr = chars[Math.floor(Math.random()*chars.length)]
randomString += rchr;
}
var genPassword = randomString.split('').sort(function(){return 0.5-Math.random()}).join('');
console.log(genPassword);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment