Last active
September 7, 2021 18:40
-
-
Save zhibirc/929b36329553d575fc18ee436e8e3d17 to your computer and use it in GitHub Desktop.
Basic password generator.
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
/** | |
* Basic password generator. | |
* Alphabet: digits, English letters in both cases, and special characters. | |
* | |
* @param {number[]} range - list of two numeric values "from" and "to" which are UTF code points | |
* @param {number} length - password length, small values aren't recommended for security reasons | |
* | |
* @return {Generator<string, void, *>} | |
*/ | |
function* generatePassword ( range = [33, 126], length = 20 ) { | |
while ( 1 ) yield String.fromCodePoint(...Array.from({length}, _ => ~~(range[0] + Math.random() * (range[1] - range[0] + 1)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment