Skip to content
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

Verifying password #17

Closed
lewispham opened this issue Aug 12, 2015 · 6 comments
Closed

Verifying password #17

lewispham opened this issue Aug 12, 2015 · 6 comments
Labels

Comments

@lewispham
Copy link

How can I verify password hashed by scrypt-async?
How is scrypt-async hash different from node-scrypt hash? Are they compatible?

@evilaliv3
Copy link
Contributor

@Tresdin:

  1. to verify a password hashed by scrypt-async you should recalculate the scrypt hash and see if it maches the one that you stored.
  2. yep aside from bugs in the implementation they should be compatible.

@lewispham
Copy link
Author

@evilaliv3 I wonder if there would be any standard instruction or specification for password verification in scrypt. Because in bcrypt, this task is complicated. You can see this post for more details.

@dchest
Copy link
Owner

dchest commented Aug 12, 2015

@Tresdin there were attempts to make a universal text encoding for scrypt (params + salt + hash), but so far there are many different implementations. All you need is just to store this information:

{
   logN: ..., // or N
   r: ...,
   p: ..., // always 1 for scrypt-async-js
   salt: ..., // possibly base64 encoded
   hash: ...,  // possibly base64 encoded
}

To verify, read parameters and salt from storage, generate a new hash with the password you're trying to verify and compare to the stored one.

@lewispham
Copy link
Author

@dchest Since derived key length is a required parameter in scrypt-async, do I need to include it into hash string? And also, what is p parameter? Why is it so important? Or do you have any source that explains these params?

@dchest
Copy link
Owner

dchest commented Aug 12, 2015

Ah, true, if you ever want to change the hash length, save it. But I'd just fix it to 32 (if you don't need more derived keys for other purposes). P is parallelization parameter: it tells how many parallel instances to calculate in order to fill more CPU cores. It's fixed to 1 in scrypt-async-js for simplicity (and because apart from web workers JS doesn't parallelize).

The source is the original scrypt paper: https://www.tarsnap.com/scrypt/scrypt.pdf

@lewispham
Copy link
Author

I used to be stuck with picking between scrypt and bcrypt for password hashing because of this issue. I think it's no longer a problem to me. Thank you so much @dchest .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants