Sum up exception if multiple categories of required characters are missing.
This commit is contained in:
3 files changed
+32
-5
No files matched your search
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" ?>
|
||||
<xliff version="1.1">
|
||||
<file datatype="php" original="src/Resources/contao/languages/de/exception.php" source-language="en" target-language="de">
|
||||
<file datatype="php" original="src/Resources/contao/languages/de/exception.php" source-language="en"
|
||||
target-language="de">
|
||||
<body>
|
||||
<trans-unit id="XPT.passwordValidation.maxLength">
|
||||
<source>Please use a maximum of %s characters.</source>
|
||||
@@ -30,6 +31,10 @@
|
||||
<source>Please use at least %u characters out of the following: %s</source>
|
||||
<target>Bitte verwenden Sie aus den folgenden Sonderzeichen mindestens %u Zeichen: %s</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="XPT.passwordValidation.required.summary">
|
||||
<source>Please use at least %u uppercase letters, %u lowercase letters, %u numbers and %u special characters: %s</source>
|
||||
<target>Bitte verwenden Sie mindestens %u Großbuchstaben, %u Kleinbuchstaben, %u Ziffern und %u Sonderzeichen: %s</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
@@ -23,6 +23,9 @@
|
||||
<trans-unit id="XPT.passwordValidation.required.other">
|
||||
<source>Please use at least %u characters out of the following: %s</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="XPT.passwordValidation.required.summary">
|
||||
<source>Please use at least %u uppercase letters, %u lowercase letters, %u numbers and %u special characters: %s</source>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
@@ -43,6 +43,7 @@ final class RequiredCharacters implements PasswordValidatorInterface
|
||||
|
||||
$password = $context->getPassword()->getString();
|
||||
|
||||
$errors = [];
|
||||
foreach ($require as $category => $minimum) {
|
||||
if (!$minimum) {
|
||||
continue;
|
||||
@@ -55,15 +56,33 @@ final class RequiredCharacters implements PasswordValidatorInterface
|
||||
|
||||
if ($actual < $minimum) {
|
||||
if ('other' === $category) {
|
||||
throw new ValidatorException(
|
||||
$errors[] = new ValidatorException(
|
||||
sprintf($this->translate('required.other'), $minimum, $configuration['other_chars'])
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new ValidatorException(sprintf($this->translate('required.' . $category), $minimum));
|
||||
$errors[] = new ValidatorException(sprintf($this->translate('required.' . $category), $minimum));
|
||||
}
|
||||
}
|
||||
|
||||
if (count($errors) > 1) {
|
||||
throw new ValidatorException(
|
||||
sprintf(
|
||||
$this->translate('required.summary'),
|
||||
$require['uppercase'],
|
||||
$require['lowercase'],
|
||||
$require['numbers'],
|
||||
$require['other'],
|
||||
$configuration['other_chars']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (count($errors) > 0) {
|
||||
throw array_pop($errors);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -89,7 +108,7 @@ final class RequiredCharacters implements PasswordValidatorInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
return \strlen(preg_replace('/[^'.$chars.']+/', '', $string));
|
||||
return \strlen(preg_replace('/[^' . $chars . ']+/', '', $string));
|
||||
|
||||
default:
|
||||
return null;
|
||||
@@ -106,7 +125,7 @@ final class RequiredCharacters implements PasswordValidatorInterface
|
||||
|
||||
$return = '';
|
||||
foreach (array_unique(preg_split('//u', $chars, -1, PREG_SPLIT_NO_EMPTY)) as $char) {
|
||||
$return .= '\\'.$char;
|
||||
$return .= '\\' . $char;
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
Reference in new issue
Block a user