Skip to content
Snippets Groups Projects
Commit dbbf2f93 authored by Mark Jones's avatar Mark Jones Committed by Kristen Pol
Browse files

#3366875 - Use mb_strlen() to more accurately calculate password length in length constraint.

parent f2f9c8da
No related branches found
No related tags found
1 merge request!59#3366875 - Use mb_strlen() to more accurately calculate password length in length constraint.
......@@ -27,13 +27,13 @@ class PasswordLength extends PasswordConstraintBase {
$validation = new PasswordPolicyValidation();
switch ($configuration['character_operation']) {
case 'minimum':
if (strlen($password) < $configuration['character_length']) {
if (mb_strlen($password) < $configuration['character_length']) {
$validation->setErrorMessage($this->formatPlural($configuration['character_length'], 'Password length must be at least 1 character.', 'Password length must be at least @count characters.'));
}
break;
case 'maximum':
if (strlen($password) > $configuration['character_length']) {
if (mb_strlen($password) > $configuration['character_length']) {
$validation->setErrorMessage($this->formatPlural($configuration['character_length'], 'Password length must not exceed 1 character.', 'Password length must not exceed @count characters.'));
}
break;
......
......@@ -86,6 +86,12 @@ class PasswordLengthTest extends UnitTestCase {
'PasswordPassword',
FALSE,
],
[
2,
'minimum',
'£',
FALSE,
],
];
}
......
......@@ -61,6 +61,7 @@ class PasswordPolicyValidator implements PasswordPolicyValidatorInterface {
*/
public function validatePassword(string $password, UserInterface $user, array $edited_user_roles = []): PasswordPolicyValidationReport {
// Stop before policy-based validation if password exceeds maximum length.
// Intentionally using `strlen` rather than `mb_strlen` to match core code.
if (strlen($password) > PasswordInterface::PASSWORD_MAX_LENGTH) {
return TRUE;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment