i always get a false compare with this line of block for unknown reason even when the user password mathes the hashed password i have in my DB. please help.
bcrypt.compare(password, user.password , function(error, result) {
console.log(result==true);
if (result === true) {
return callback(null, user);
} else {
return callback();
}
})
});
}
// hash password before saving to database
UserSchema.pre('save', function(next) {
var user = this;
bcrypt.hash(user.password, 10, function(err, hash) {
if (err) {
return next(err);
}
user.password = hash;
next();
})
});
full project and code can be found here: https://github.com/eladnm/Trinity-Management-System-
Perhaps, result === true
returns false as result might not be an actual true value. It could be a truthly value and which when compared with ==
returns true. (From bcrypt's npm )
You could simply write:
if (err) {
return callback(err);
}
if (result) {
return callback(null, user);
}
return callback();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.