Skip to content

Instantly share code, notes, and snippets.

@hilyin
Created February 24, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilyin/33b696bd6f6ceb3abfff867edc689b8c to your computer and use it in GitHub Desktop.
Save hilyin/33b696bd6f6ceb3abfff867edc689b8c to your computer and use it in GitHub Desktop.
Password Generator
#!/usr/bin/env node
var passwordLength = 20;
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+-=[]{}\\|:;\"'<,>.?/'\"";
if (typeof process.argv[2] !== 'undefined') {
passwordLength = parseInt(process.argv[2]);
if (passwordLength < 10) {
console.log('You should really use a larger password.');
}
}
var makePassword = function () {
var text = "";
for (var i = 0; i < passwordLength; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
console.log('Permutations possible: ' + Math.pow(possible.length, passwordLength));
for (var x = 0; x < 5; x++) {
console.log(makePassword() + ' ' + makePassword() + ' ' + makePassword());
}
@hilyin
Copy link
Author

hilyin commented Feb 24, 2017

TODO: math.random is not crypto secure, use https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
uses a higher quality entropy source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment