Skip to content

Instantly share code, notes, and snippets.

@mariosal

mariosal/password.js

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.