1

I am using bcrypt package to generate encrypt passwords. I am using the code below to encrypt the password:

let bcrypt = require('bcrypt');
var hash = bcrypt.hashSync(password, 10);

It returns different hash for same password. But my requirement is that I need same hash for same password. Please let me is it possible using bcrypt package. If not please suggest me different package that I can use?

EDIT: I am using oauth2-server package. And with this package I am generation token. So in this package there is no way to compare the hash. As that work is handled internally by the package. So I am looking for package that can give me same hash.

Tavish Aggarwal
  • 1,020
  • 3
  • 22
  • 51
  • 1
    Why do you need the same hash? – Abhyudit Jain Jan 02 '18 at 06:10
  • @AbhyuditJain That is what my requirement is. I am comparing the hash as stored in database. – Tavish Aggarwal Jan 02 '18 at 06:11
  • I would say, that might not be the correct approach. I am not sure about the exact requirement though, but being different hash every time is what I've seen so far. Why do you need to compare stored hashed password in db ? – Aman Gupta Jan 02 '18 at 06:13
  • Possible duplicate of [Bcrypt generates different hashes for the same input?](https://stackoverflow.com/questions/8467819/bcrypt-generates-different-hashes-for-the-same-input) – Kay Jan 02 '18 at 06:18
  • @agpt.. Updated question – Tavish Aggarwal Jan 02 '18 at 06:22
  • @TavishAggarwal You should get user's password in login api all, verify it using bcrypt.verify and then if it's verified, geenrate token. – Abhyudit Jain Jan 02 '18 at 06:33
  • 1
    @TavishAggarwal, why you are thinking to compare your hashed password with `==` method ? Try instead `bycrypt.compare()` method. They can compare your password as well. – Ataur Rahman Munna Jan 02 '18 at 06:37

0 Answers0