Skip to content

Instantly share code, notes, and snippets.

@craigmaslowski
Last active August 29, 2015 14:00
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 craigmaslowski/f9b7aff3205980326fe1 to your computer and use it in GitHub Desktop.
Save craigmaslowski/f9b7aff3205980326fe1 to your computer and use it in GitHub Desktop.
Quick and dirty password generator

Quick and Dirty Password Generator

Generates a random string twelve characters in length by default. Accepts an optional command line parameter for specifying password length. Requires node.js

Installation

Put the file on your drive.

chmod 755 pw

Examples

> ./pw
yJrenPAL7JfY

> ./pw 20
g3qwQULV20n4mQJI8lqV
#!/usr/bin/env node
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghiklmnopqrstuvwxyz',
length = !isNaN(process.argv[2]) ? process.argv[2] : 12;
string = '';
for (var i = 0; i < length; i++) {
var randomNumber = Math.floor(Math.random() * chars.length);
string += chars.substring(randomNumber, randomNumber + 1);
}
console.log(string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment