treehouse-projects/javascript-authentication-with-express-and-mongo

bcrypt with nodejs compare always false. login fails

Opened this issue · 0 comments

i always get a false compare with this line of block for unknown reason even when the user password matches the hashed password i have in my DB. and login fails.

` 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();
  })
});`