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."


Solution:Jump to 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
6 Replies
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
hi, log the hashed password n the serial monitor and compare with the one saved in database and check if is the same,
@wafa_athmani you could still make use of cryptjs , it's easier to use
I double checked and it's the same
Well as I said early try other simpler password hashing libraries
I will try and keep you updated, thanks