I'm getting an [Error: data and hash arguments required]
error when trying to verify a user's existing password within my node app. The context is that I ask my user to verify their existing password prior to changing it within the user profile page. My stack is node + mondodb (via mongoose) using passport-local with bcrypt.
The relevant code is:
// 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
references the current user object, and `req.body.password' is the password obtained from the user's POST. I am using the UserSchema, passport strategy and Bcrypt configuration from the passport-local example here.
Can someone provide guidance on how to verify that the passwords match prior to updating?
So bcrypt.compare
is complaining that one of the arguments, either data
or hash
are missing. So that implies perhaps this.password
is returning null
or undefined
. Check your database record for that user and be sure it has a valid hash stored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With