I'm trying to authenticate the user based on a password. I'm using bcrypt compare to compare user requested password and one in mongodb but even though two password matches perfectly I get null value, here is the code which I"m trying
userSchema.methods.comparePassword = function (passw, cb) {
var user = this;
console.log((passw === user.password) ? 'passwords match' : 'passwords dont match' );
bcrypt.compare(passw, user.password, function (err, isMatch) {
console.log(passw +" "+ user.password +" " +isMatch )
if(err) {
return cb(err)
}
cb(null, isMatch)
})
}
I get the console output as below
sh37xb sh37xb null
which are user-entered password, password in database for that user, and isMatch value which is null instead it has to be the opposite since both passwords match perfectly. when I checked this password with the ternary condition it says 'passwords match' but not with bcrypt.compare. What am I doing wrong? can anyone help me to point out my mistake??