I hash my password and save a user into db (using passport). Now I wrote an api (without passport) try to compare the password, it returned false although I key in the same string. Just curious why does it so? I doubt I know about how bCrypt works now. My code as below.
my model
module.exports.comparePassword = function(candidatePassword, hash, callback){
bCrypt.compare(candidatePassword, hash, function(err, isMatch){
if(err){
return callback(err);
} else {
console.log("model: " + isMatch)
callback(null, isMatch);
}
});
}
controller http://pastebin.com/jCB4YUy0
Figured it out. I need no to hash the password. The bCrypt module has that built in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.