【发布时间】:2013-08-04 08:56:10
【问题描述】:
尝试在我的节点应用程序中验证用户的现有密码时,我收到 [Error: data and hash arguments required] 错误。上下文是我要求我的用户在用户个人资料页面中更改密码之前验证他们现有的密码。我的堆栈是使用本地护照和 bcrypt 的节点 + mondodb(通过猫鼬)。
相关代码为:
// code trying to match that returns the aforementioned error
req.user.comparePassword(req.body.password, function (err, isMatch) {
if (err) {
return console.error(err);
}
if (isMatch) {
console.log('passwords match');
// now save new password
// Password verification
userSchema.methods.comparePassword = function (candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, function (err, isMatch) {
if (err) return cb(err);
cb(null, isMatch);
});
};
}
}
req.user引用当前用户对象,`req.body.password'是从用户POST获取的密码。我正在使用来自本地护照示例 here. 的 UserSchema、护照策略和 Bcrypt 配置
有人可以提供有关如何在更新之前验证密码是否匹配的指导吗?
【问题讨论】:
标签: node.js authentication mongoose bcrypt passport.js