Answer the question
In order to leave comments, you need to log in
Why isMatch is always false?
Why isMatch is always false? If you print candidatePassword and this.password, then they are the same.
userSchema.methods.comparePassword = function comparePassword(candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, (err, isMatch) => {
cb(err, isMatch);
});
};
userScema.pre('save', function preSave(next) {
const user = this;
if (!user.isModified('password')) { return next();}
bcrypt.genSalt(10, (err, salt) => {
if (err) {return next(err); }
bcrypt.hash(user.password, salt, (err, hash) => {
if (err) {return next(err);}
user.password = hash;
next();
});
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question