Skip to content

Instantly share code, notes, and snippets.

@wereHamster
Created July 13, 2013 08:12
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 wereHamster/5989944 to your computer and use it in GitHub Desktop.
Save wereHamster/5989944 to your computer and use it in GitHub Desktop.
Generate a random password from as many keys as there are on a standard US layout keyboard.
#!/usr/bin/env node
var chars =
[ 'abcdefghijklmnopqrstuvwxyz'
, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
, '1234567890'
, '~!@#$%^&*()_a+'
, '`-='
, '[]{}o\'O",./<>?'
].join();
var secret = ''
, length = parseInt(process.argv[process.argv.length - 1]) || 30;
for (var i = 0; i < length; ++i) {
secret = secret + chars[Math.floor(Math.random() * chars.length)];
}
console.log(secret);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment