I am using "bcrypt": "^3.0.4" and I have the latest stable version of node. The issue I am facing is when the user attempts to login. With the correct password the initial login attempt is always unsuccessful while the second attempt is successful. I would like to know where I am getting it wrong. The assumption here is that the user has entered an email/username that is available in the database, mongodb in this case.
User.findOne({ "email": user.email }, (err, ruser) => {
if (err) {
res.send(err);
}
else {
bcrypt.hash(user.password, 10, function (err, hash) {
if (err) {
console.log(err);
}
else {
bcrypt.compare(user.password, hash).then(function (res) {
if (res) {
pass = true;
}
else {
pass = false;
}
});
res.json(pass);
}
});
}
});
Thank you in advance.
logsat failure timebcrypt.hash(user.password, 10 ..and retried, but the outcome is the same.console.log(ruser.password)shows the password as retrieved from the database.