Skip to content

Instantly share code, notes, and snippets.

@cjuroz
Last active July 5, 2018 05:39
Show Gist options
  • Save cjuroz/8e7a644976ce9dfd8eadeeb6c212dd01 to your computer and use it in GitHub Desktop.
Save cjuroz/8e7a644976ce9dfd8eadeeb6c212dd01 to your computer and use it in GitHub Desktop.
Simple password hash/salt generator for Secure Coding Dojo
// 1) Fill password var with your secret password.
// 2) Contact secure coding dojo admin to update generated hash/salt values.
const crypto = require('crypto');
const validator = require('validator');
password = 'insert-your-password-here';
var isStrongPass = validator.matches(password,/.{8,}/)==true && validator.matches(password,/[a-z]{1,}/)==true && validator.matches(password,/[A-Z]{1,}/)==true && validator.matches(password,/[0-9]{1,}/)==true;
if(!isStrongPass){
console.log("Select a password that is long enough (8 or more characters), at least one lower character, one capital character and one digit.");
process.exit();
}
function hashPassword(password, saltString) {
var salt = new Buffer(saltString, 'base64');
var passwordHash = crypto.pbkdf2Sync(password, salt, 10000, 64, 'SHA512').toString('base64');
return passwordHash;
}
var passSalt = crypto.randomBytes(16).toString('base64').toString();
var passHash = hashPassword(password, passSalt);
console.log("hash " + passHash);
console.log("salt " + passSalt);
@cjuroz
Copy link
Author

cjuroz commented Jul 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment