Skip to content

Instantly share code, notes, and snippets.

@mariosal
Last active August 29, 2015 14:04
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 mariosal/68d27c37e8371ab75c36 to your computer and use it in GitHub Desktop.
Save mariosal/68d27c37e8371ab75c36 to your computer and use it in GitHub Desktop.
Password Generator
/*
* Written in 2014 by Mario Saldinger <mariosaldinger@gmail.com>
*
* To the extent possible under law, the author(s) have dedicated all copyright and
* related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along with
* this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
'use strict';
var crypto = require('crypto');
var PASSWORD_LENGTH = 34;
var ALPHABET =
'123456789' +
'QWERTYUP' +
'ASDFGHJKL' +
'ZXCVBNM' +
'qwertyuiop' +
'asdfghjk' +
'zxcvbnm';
var password = new Array(PASSWORD_LENGTH);
var randomBytes = crypto.randomBytes(PASSWORD_LENGTH);
for (var i = 0; i < PASSWORD_LENGTH; ++i) {
password[i] = ALPHABET[randomBytes[i] % ALPHABET.length];
}
process.stdout.write(password.join(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment