diff options
author | Joas Schilling <coding@schilljs.com> | 2021-02-17 15:14:36 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-02-17 15:21:12 +0300 |
commit | 78103f9408f08cbd0636aec7bee09006df3c72fe (patch) | |
tree | 94aeacd071f82ffed70d637ffa668cec1d487c27 /lib | |
parent | 49f2975209cf04cab62a8daccb6a0e4ff0dd1397 (diff) |
Check all password requirements in one attempt
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/PasswordValidator.php | 17 | ||||
-rw-r--r-- | lib/Validator/LengthValidator.php | 4 | ||||
-rw-r--r-- | lib/Validator/NumericCharacterValidator.php | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/lib/PasswordValidator.php b/lib/PasswordValidator.php index 9391a87..6c79128 100644 --- a/lib/PasswordValidator.php +++ b/lib/PasswordValidator.php @@ -63,6 +63,8 @@ class PasswordValidator { HIBPValidator::class, ]; + $errors = []; + $hints = []; foreach ($validators as $validator) { try { /** @var IValidator $instance */ @@ -73,8 +75,19 @@ class PasswordValidator { continue; } - $instance->validate($password); + try { + $instance->validate($password); + } catch (HintException $e) { + $errors[] = $e->getMessage(); + $hints[] = $e->getHint(); + } } - } + if (!empty($errors)) { + throw new HintException( + implode(' ', $errors), + implode(' ', $hints), + ); + } + } } diff --git a/lib/Validator/LengthValidator.php b/lib/Validator/LengthValidator.php index 400d444..bf45737 100644 --- a/lib/Validator/LengthValidator.php +++ b/lib/Validator/LengthValidator.php @@ -43,9 +43,9 @@ class LengthValidator implements IValidator { public function validate(string $password): void { $minLength = $this->config->getMinLength(); if(strlen($password) < $minLength) { - $message = 'Password needs to be at least ' . $minLength . ' characters long'; + $message = 'Password needs to be at least ' . $minLength . ' characters long.'; $message_t = $this->l->t( - 'Password needs to be at least %s characters long', [$minLength] + 'Password needs to be at least %s characters long.', [$minLength] ); throw new HintException($message, $message_t); } diff --git a/lib/Validator/NumericCharacterValidator.php b/lib/Validator/NumericCharacterValidator.php index 1d0955e..cc15c88 100644 --- a/lib/Validator/NumericCharacterValidator.php +++ b/lib/Validator/NumericCharacterValidator.php @@ -44,7 +44,7 @@ class NumericCharacterValidator implements IValidator { $enforceNumericCharacters = $this->config->getEnforceNumericCharacters(); if($enforceNumericCharacters) { if (preg_match('/^(?=.*\d).+$/', $password) !== 1) { - $message = 'Password needs to contain at least one numeric character'; + $message = 'Password needs to contain at least one numeric character.'; $message_t = $this->l->t( 'Password needs to contain at least one numeric character.' ); |