[11.x] Prevent the max password length validator exceeding bcrypt limit #52269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
\Illuminate\Validation\Rules\Password::max
method sets the$max
property of the Password validator to any number. Thebcrypt
password hashing algorithm, which Laravel uses by default, cannot handle passwords longer than 72 bytes, and anything submitted beyond that will simply be silently truncated. Thus if a user sets this to a large number (I encountered it in an app which had set it to 500), it will not cause a validation error even if the password is actually unusable.This limit does not apply to the newer
argon
andargon2id
hashing functions.This change sets a simple rule that if the requested size is bigger than 72, and the selected password hashing driver is
bcrypt
, it setsmax
to 72 so that even if user code sets it higher, it will still cause correct validation errors.Given the way that the
min
value in the same class is handled, it might also be appropriate to ensure thatmax
>min
, but I wanted to limit this PR to just a single concern.