Last active
July 5, 2018 05:39
-
-
Save cjuroz/8e7a644976ce9dfd8eadeeb6c212dd01 to your computer and use it in GitHub Desktop.
Simple password hash/salt generator for Secure Coding Dojo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added to repl.it: https://repl.it/@cjuroz/genpassforsecurecodingdojo