I get an error [Error: data and hash arguments required] when I try to verify an existing user password in my node application. The context is that I ask my user to verify their existing password before changing it on the user profile page. My stack is node + mondodb (via mongoose) using passport-local with bcrypt.
Relevant Code:
// 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 refers to the current user object, and `req.body.password 'refers to the password received from the POST user. I use UserSchema, passport strategy and Bcrypt configuration from the local passport example here.
Can someone give instructions on how to verify that passwords match before upgrading?
source share