Skip to content
Advertisement

Bcrypt.compare always returns true

I am using NestJS and Passport to create a simple log in/registration form and I am using bcrypt to see if the password that has been hashed is matching the password that user provides in the login form, but it always returns true

JavaScript

In the code above, even if I set the argument as a string it will return true and go inside the if statement, which should be false.

Advertisement

Answer

As the compare function of the returns a promise, you need to await it. Try this:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement