Created
October 28, 2019 14:18
-
-
Save devcem/59c42f7d3d377f1633caa954978a2a26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lowerCase = 'abc'; | |
var upperCase = 'ABC'; | |
var symbols = '*!?'; | |
//make strings array | |
lowerCase = lowerCase.split(''); | |
upperCase = upperCase.split(''); | |
symbols = symbols.split(''); | |
function selectRandom(set){ | |
return set[Math.floor(Math.random() * set.length)]; | |
} | |
function generatePassword(options){ | |
var passwordOutput = ''; | |
for(var i = 0; i < options.length; i++){ | |
//shuffle | |
var randomIndex = Math.floor(Math.random() * options.characterSet.length); | |
var randomCharacterFromSet = options.characterSet[randomIndex]; | |
var randomCharacter = selectRandom(randomCharacterFromSet); | |
passwordOutput+=randomCharacter; | |
} | |
return passwordOutput; | |
} | |
generatePassword({ | |
length : 10, | |
characterSet : [lowerCase, upperCase, symbols], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment