Dependency on password generator can lead to invalid usernames ("The username contains an illegal character.")

Created on 26 October 2023, about 1 year ago
Updated 21 November 2023, about 1 year ago

Problem/Motivation

When setting a temporary username, Email Registration invokes the "password_generator" service, which defaults to \Drupal\Core\Passwrd\DefaultPasswordGenerator, to generate a "unique" hash. This happens in three areas:

- email_registration_form_user_form_alter()
- EmailRegistrationCompletionRegistration->buildPaneForm()
- EmailRegistrationLogin->buildPaneForm()

While this works fine out of the box with the default generator, it is possible to replace / decorate the default generator service, which can allow for a different set of characters to be used in the generated password. This leads to the possibility of invalid username characters in the temporary hash and validation errors when registering users. A concrete case of this is the Generate Password module ( https://www.drupal.org/project/genpass β†’ ) where branch 2.0 allows an option for overriding the default password generator service

Steps to reproduce

- Enable Email Registration module
- Install and enable Generate Password module (2.0 branch) and enable genpass setting to override default Drupal password generator
- Attempt to register a new user account; validation will likely fail using the default genpass password algorithm (there is a slim chance that the algorithm will select a safe special character; 5 out of 29 special characters allowed by genpass would pass the preg check in email_registration_cleanup_username())

Proposed resolution

There are two possible paths:

1) Replace the password generator calls with a custom hash generation algorithm
2) Subject each of the invocations of the password generator to the safety mechanism in email_registration_cleanup_username()

Remaining tasks

Select best solution and patch

User interface changes

None

API changes

See above

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tkiehne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024