-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bcrypt generating different hash when assigning same hash #1027
Comments
same issue |
Hy i just found the bug what went wrong after spinning my head all day this the behaviour you've encounter is expected lemme tell you why is that so you're something like that user.name='sameer' |
same issue |
The issue arises from pre-save hooks, which are middleware functions invoked before the document is saved, being called before the document is saved. This results in the generation of different hashed passwords. pls check your schema. |
I've run into the same problem which's like compare always returns false but with some strange behaviour.
so I've tried every solution which in previous closed (bcrypt returning false) were mentioned(mostly regarding the length issue)
But here's strange thing behavior I found
the thing is here
hashpassword
is$2b$10$8UMFhEZrwc85vytIGyE2v.mX3CYU/ANojK8ZeaO2bXPs5Lttis7sq
but after storing this hash in a variable and storing into the db I found the hash was different
$2b$10$ELPnmKkLLvrPW7QCVSrIp.c3Jn5VuoTsEL7OKnJ5QnJe6ZC2jYb6q
why is that assigning to the variable and storing in database making different hash
i've also tried this
where I'm storing the hash directly and literally I've manually compared the hash and hash is same but it doesn't seem to work at this point, I've given up
I'm using MongoDB and Mongoose and here's my schema constraint(length tries)
The interesting part here is that it works on the simple register/login user fine for example
when I try to log in it'll actually work fine and compare doesn't return false
package version
OS Version
The text was updated successfully, but these errors were encountered: