3

I using bcrypt to create a password hash and in the php documentation it says

Caution: Using the PASSWORD_BCRYPT for the algo parameter, will result in the password parameter being truncated to a maximum length of 72 characters.

If I allow users to type more than 72 characters it's like I fooling them because they not using the passsword that they think that they use. So my question is do I need to set maximum length or not

6

Well Dmitry is right when he says 72 characters is good. If the characters are random enough. (1.78 bits per character).

You can use the approach described (security warning that password is "too long"). Or simply limit password length (with security warning).

If you expect your users to enter more than 72 characters, you could as well use SHA-512 to prehash the password, so you'd feed the hash into the bcrypt (as password) and not the actual password. There are no security issues with this approach. However it is non-standard, so if you do need to provide interopability with other applications (not yours) you can't use it.

1

I wouldn't worry about it. 72 characters is a quite decent password length, and password truncation is a common practice. Your users will trust you with many security options (like hash algorithm and the number of iterations) which affect security much more than password length.

Implementing a warning wouldn't hurt though, that is, if you have nothing else to implement instead.

  • 1
    Or: "72 characters is the same size as this sentence; don't worry about it :)" – Maarten Bodewes Apr 13 '15 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.