Last active
March 7, 2016 13:24
-
-
Save mjethani/89950960d4be3ae26215 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
#!/usr/bin/env node | |
// usage: passcode [<length>] | |
var crypto = require('crypto') | |
function randomPasscode(length) { | |
var passcode = '' | |
for (var i = 0; i < length; i++) { | |
passcode += Math.floor(crypto.randomBytes(1).readUInt8() * 10 / 0x100) | |
} | |
return passcode | |
} | |
function main() { | |
if (process.argv[2] === '--help' || process.argv[2] === '-h' || | |
process.argv[2] === '-?') { | |
console.log('usage: passcode [<length>]\n') | |
process.exit() | |
} | |
console.log(randomPasscode(+process.argv[2] || 11)) | |
} | |
if (require.main === module) { | |
main() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment