[英]compare password with bCrypt returned false
I hash my password and save a user into db (using passport). 我对密码进行哈希处理并将用户保存到db(使用通行证)。 Now I wrote an api (without passport) try to compare the password, it returned false although I key in the same string.
现在,我写了一个api(没有护照)尝试比较密码,尽管我输入了相同的字符串,但它返回了false。 Just curious why does it so?
只是好奇为什么会这样? I doubt I know about how bCrypt works now.
我怀疑我是否知道bCrypt现在如何工作。 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 控制器http://pastebin.com/jCB4YUy0
Figured it out. 弄清楚了。 I need no to hash the password.
我不需要哈希密码。 The bCrypt module has that built in.
bCrypt模块具有内置模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.