Created
February 24, 2017 21:33
-
-
Save hilyin/33b696bd6f6ceb3abfff867edc689b8c to your computer and use it in GitHub Desktop.
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
#!/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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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