使用passport-local和bcrypt在node.js中检查和更新密码
当我尝试在我的节点应用程序中validation用户的现有密码时,出现[Error: data and hash arguments required]
错误。 上下文是我要求我的用户在用户configuration文件页面中更改之前validation其现有的密码。 我的堆栈是node + mondodb(通过mongoose)使用passport-local与bcrypt。
相关的代码是:
// 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获得的密码。 我在这里使用护照本地示例中的UserSchema,护照策略和Bcryptconfiguration。
有人可以提供有关如何在更新之前validation密码是否匹配的指导?
所以bcrypt.compare
抱怨其中一个参数, data
或hash
丢失。 所以这意味着也许this.password
返回null
或undefined
。 检查你的数据库logging,并确保它有一个有效的散列存储。
- 用户login页面刷新不适用于Passport js
- 基本node.js表示authentication不起作用
- 如何使用Django身份validation在Node应用程序中对用户进行身份validation?
- 如何访问passport.deserializeUser中的node-orm2 Express中间件
- Node.jsauthentication没有护照:是json的networking令牌可靠吗?
- 当它不应该时,authentication返回“401(未授权)”
- Firebase 3 node.js服务器authentication是否会改变?
- Nodejs我需要使用Passport吗?
- Nodejs,通过httpsauthentication并redirect到http