Created
March 22, 2013 18:01
-
-
Save ben-ng/5223411 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
User.verifyPassword = function (password, hash, callback) { //You need a callback because bcrypt.compare is async | |
bcrypt.compare(password, hash, function(err, isMatch) { | |
callback(err, isMatch); | |
}); | |
} | |
//Usage: | |
exports.User.verifyPassword(password, user.password, function(err, isMatch) { | |
if(err) { | |
console.log("Error!"); | |
throw err; | |
} | |
else { | |
if(isMatch) { | |
done(err,user); | |
} | |
else { | |
done(err,false); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment