Why does bcrypt password comparison fail in my Node.js + MongoDB login system?

Good morning everyone,i did a login system using node.js + mongodb, and I used bcrypt to encrypt the password. It encrypts fine and is stored in the database. But when I try to log in and compare the entered password with the encrypted password stored in the database, it always returns false, indicating they don't match. I've searched a lot on Stack Overflow and even tried AI, but I couldn't find a solution. If anyone knows the solution or has encountered this before, Note: I've encountered this before, and the reason was a column in a MySQL database being limited to 50 characters while it needed 500, but in this case, I couldn't figure it out because MongoDB is not MySQL."
attachment 0
attachment 1
Solution:
I would suggest you console the value of "hash" , that's coming from the argument you passed through your bcrypt.hash() method. Check if the value of the hash argument is a string of the actual hashed password
Jump to solution
6 Replies
Solution
Marvee Amasi
Marvee Amasi13mo ago
I would suggest you console the value of "hash" , that's coming from the argument you passed through your bcrypt.hash() method. Check if the value of the hash argument is a string of the actual hashed password
youcef_ali
youcef_ali13mo ago
hi, log the hashed password n the serial monitor and compare with the one saved in database and check if is the same,
Marvee Amasi
Marvee Amasi13mo ago
@wafa_athmani you could still make use of cryptjs , it's easier to use
wafa_athmani
wafa_athmani13mo ago
I double checked and it's the same
Marvee Amasi
Marvee Amasi13mo ago
Well as I said early try other simpler password hashing libraries
wafa_athmani
wafa_athmani13mo ago
I will try and keep you updated, thanks

Did you find this page helpful?