From 5cb1705cd40bdbc60d5879faed2efd20fb103a0e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 22 Oct 2024 14:54:44 +0200 Subject: [PATCH] fix(generation): Fix common-password check when we accidentally hit the same password length again Signed-off-by: Joas Schilling --- lib/Validator/CommonPasswordsValidator.php | 2 +- tests/lib/Validator/CommonPasswordsValidatorTest.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Validator/CommonPasswordsValidator.php b/lib/Validator/CommonPasswordsValidator.php index c65bce26..9974a7d3 100644 --- a/lib/Validator/CommonPasswordsValidator.php +++ b/lib/Validator/CommonPasswordsValidator.php @@ -28,7 +28,7 @@ public function validate(string $password): void { $enforceNonCommonPassword = $this->config->getEnforceNonCommonPassword(); $passwordFile = __DIR__ . '/../../lists/list-'.strlen($password).'.php'; if ($enforceNonCommonPassword && file_exists($passwordFile)) { - $commonPasswords = require_once $passwordFile; + $commonPasswords = require $passwordFile; if (isset($commonPasswords[strtolower($password)])) { $message = 'Password is among the 1,000,000 most common ones. Please make it unique.'; $message_t = $this->l->t( diff --git a/tests/lib/Validator/CommonPasswordsValidatorTest.php b/tests/lib/Validator/CommonPasswordsValidatorTest.php index 5378cfe9..8283440b 100644 --- a/tests/lib/Validator/CommonPasswordsValidatorTest.php +++ b/tests/lib/Validator/CommonPasswordsValidatorTest.php @@ -72,11 +72,15 @@ public function testValidate(string $password, bool $enforced, bool $valid) { } public function dataValidate() { - return [ + $attempts = [ ['banana', false, true], ['bananabananabananabanana', false, true], ['banana', true, false], ['bananabananabananabanana', true, true], ]; + for ($i = 1; $i <= 39; $i++) { + $attempts[] = [str_repeat('$', $i), true, true]; + } + return $attempts; } }