Skip to content

Instantly share code, notes, and snippets.

@SomeoneWeird
Created August 1, 2014 13:33
Show Gist options
  • Save SomeoneWeird/a882dd8303c30389e7f4 to your computer and use it in GitHub Desktop.
Save SomeoneWeird/a882dd8303c30389e7f4 to your computer and use it in GitHub Desktop.
function makePass(pass, done) {
crypto.randomBytes(10, function(err, bytes) {
if(err) return done(err);
var s = bytes.toString('hex');
done(makeHash(pass, s));
});
}
function makeHash(pass, salt) {
return salt + "$" + require('crypto').createHmac('sha256', salt).update(pass).digest('hex');
}
function checkPass(pass, hash) {
var tmp = hash.split('$');
if(!tmp || tmp.length != 2) return false;
var salt = tmp[0];
return hash === makeHash(pass, salt)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment