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.

Command icon 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

arcaic created an issue. See original summary.

arcaic’s picture

Issue summary: View changes
santanu mondal’s picture

Working on it..

fox mulder’s picture

Thanks 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):

  'bruteforce' => t('Your password is too weak'),
  'regex' => t('Your password must not match a common pattern'),
  default => t('Your password is too weak'),

This way users get proper feedback about their password, and we're safe if Zxcvbn adds new pattern types in the future.

santanu mondal’s picture

I have added the solution i have produce this issue and update the solution and now the WSOD error solved.

santanu mondal’s picture

Status: Active » Needs review
fox mulder’s picture

MR !4 works as expected tested on:
php: 8.3
drupal core: 11.2
better_passwords: 2.2.1

dtfabio’s picture

StatusFileSize
new58.8 KB

When 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).

Error when using password with bruteforce characters

scottsawyer’s picture

I 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.

UnhandledMatchError: Unhandled match case '...' in better_passwords_validate() (line 132 of /web/modules/contrib/better_passwords/better_passwords.module).

Does this look like the same issue?

panleevan’s picture

I had UnhandledMatchError: Unhandled match case 'bruteforce' error. Patch #4 fixed the issue. Thanks

fox mulder’s picture

Following up on #9 (dtfabio):
MR !4 correctly adds 'bruteforce' => NULL and default => NULL to the match expressions, but since the result is immediately assigned via $matches[] = match(...), the NULL still gets pushed into the array. When implode() 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).

glekli’s picture

I also encountered this problem. The patch in #12 solved it for me.

astonvictor made their first commit to this issue’s fork.

astonvictor’s picture

Version: 2.2.1 » 2.x-dev
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.