Created
October 23, 2019 10:59
-
-
Save deanacus/73d63c49c74b548bebdd2d877cae9a15 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
const lower = 'abcdefghijklmnopqrstuvwxyz'; | |
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
const numbers = '0123456780'; | |
const symbols = '!@#$%^&*_+-/~?' | |
/** | |
* Generate a password from any number os groups of strings | |
* | |
* @example generatePassword([upper, symbols], 26) | |
* | |
* @param {Array} options Array of strings to generate password from | |
* @param {Number} length Length of desired password | |
* | |
* @return {String} | |
*/ | |
const generatePassword = (options = [], length=12) => { | |
const str = [].concat(...options).join(''); | |
let password = ''; | |
for (let i = 0; i < length; i++) { | |
password += str[Math.floor(Math.random() * str.length)] | |
} | |
return password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment