Created
August 1, 2014 13:33
-
-
Save SomeoneWeird/a882dd8303c30389e7f4 to your computer and use it in GitHub Desktop.
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
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