Skip to content

Instantly share code, notes, and snippets.

@ryan-blunden
Created October 31, 2011 01:37
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 ryan-blunden/1326709 to your computer and use it in GitHub Desktop.
Save ryan-blunden/1326709 to your computer and use it in GitHub Desktop.
Random password generator
#!/usr/bin/env node
/**
* Create a random password of variable length and copy it to the clipboard
* Usage: 'random_password 4' produces a 4 character password
*/
var pass = '';
while(pass.length < process.argv[2]) {
pass += String.fromCharCode(Math.floor(35 + (Math.random() * 91)));
};
require('child_process').exec('echo '+ pass.replace('`', ' ') +' | pbcopy', function(error, stdout, stderr) {
console.log('Password copied to clipboard');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment