bcrypt-nodejs compare method returns false every time bcrypt-nodejs compare method returns false every time mongoose mongoose

bcrypt-nodejs compare method returns false every time


Most likely the root of the problem is that the compare function is returning false because you are indeed comparing two non-identical hashes.

You appear to be passing in a string 'user.login.local.password' instead of the actual password in your userSchema pre save function:

e.g. thisbcrypt.hash('user.login.local.password', null, null, function(err, hash){ should be bcrypt.hash(user.login.local.password, null, null, function(err, hash){ (no single-quotes on the password being passed in as the first parameter.)

Additionally, you're then setting the generated hash to a 'user' object which seems to live outside of your user model. I can't see that code, but I suspect that you're not updating the value of the hash on the user model being saved to mongoDB.

e.g.user.login.local.password = hash;should probably bethis.login.local.password = hash;