Skip to content

Instantly share code, notes, and snippets.

@ben-ng
Created March 22, 2013 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-ng/5223411 to your computer and use it in GitHub Desktop.
Save ben-ng/5223411 to your computer and use it in GitHub Desktop.
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