Problem/Motivation
If a password of "Password1234!" is entered then a WSOD is the result.
The ZxcvbnPhp passwordStrength function seems to return two issues with this password. The first is "Password123" being a "dictionary" pattern and the remainder "4!" being a "bruteforce" pattern.
Unfortunately better_passwords_validate does not handle the bruteforce sequence and the match produces an error.
Steps to reproduce
Install/enable as usual, register new account and enter a password of "Password1234!". Submit form and WSOD is result.
Proposed resolution
Not being sure who is at fault here so I'm not sure of the correct fix.
Should "4!" be returned as an issue from the passwordStrength module? If not the issue is in the ZxcvbnPhp library but if that's expected then the module should handle it gracefully but I'm not sure ignoring it is best.
For the patch attached I have simply added a try catch (ignore) around the match function so any unknown pattern returned by passwordStrength will be ignored.
Patch is against 2.2.1
Remaining tasks
Consider a more appropriate solution to this issue.
Issue fork better_passwords-3560435
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
arcaicComment #3
santanu mondal commentedWorking on it..
Comment #4
fox mulder commentedThanks for the patch, but I'm not sure the try-catch approach is the best solution here.
Problem with empty catch block
The empty catch block means users won't see any error message when their password triggers a bruteforce pattern (or other unhandled patterns). They won't understand why their password is being rejected.
Better approach
We should handle all pattern types explicitly. Looking at the Zxcvbn library, these patterns exist:
- bruteforce (this is what causes the error)
- date
- dictionary
- digit
- regex
- repeat
- sequence
- spatial
- year
We should add the missing ones to both match expressions (lines 121 and 132):
This way users get proper feedback about their password, and we're safe if Zxcvbn adds new pattern types in the future.
Comment #6
santanu mondal commentedI have added the solution i have produce this issue and update the solution and now the WSOD error solved.
Comment #7
santanu mondal commentedComment #8
fox mulder commentedMR !4 works as expected tested on:
php: 8.3
drupal core: 11.2
better_passwords: 2.2.1
Comment #9
dtfabio commentedWhen using the password t1234567 during testing, the site crashed. The patch in comment #4 fixed the problem for me.
Core version: 10.5.8
PHP version: 8.3.27
MySQL version: 8.4.5
better_passwords: 2.2.1
I also tried MR #4, but found this to be a less clean solution, as with the patch the user gets feedback on the problem.
However, when using the changes from the MR, just an empty password warning is printed.
This shows up as an empty list item between the possible problems with the password (see screenshot).
Comment #10
scottsawyerI don't know enough to tell if the error I am receiving is related to this issue or if it's a new issue, so please let me know if I should create a new issue.
I am seeing a lot of these messages in watchdog.
Does this look like the same issue?
Comment #11
panleevan commentedI had UnhandledMatchError: Unhandled match case 'bruteforce' error. Patch #4 fixed the issue. Thanks
Comment #12
fox mulder commentedFollowing up on #9 (dtfabio):
MR !4 correctly adds
'bruteforce' => NULLanddefault => NULLto the match expressions, but since the result is immediately assigned via$matches[] = match(...), theNULLstill gets pushed into the array. Whenimplode()renders the error list, it produces an empty<li></li>bullet.The fix is to add
array_filter()to strip null values before building the error message. The attached patch combines the bruteforce/default handling from MR !4 with this fix, applied against the 2.x branch.I'm attaching a patch against the current dev version (with MR !4 already applied).
Comment #13
glekli commentedI also encountered this problem. The patch in #12 solved it for me.
Comment #18
astonvictor commented