diff --git a/src/Symfony/Component/Validator/Constraints/PasswordStrength.php b/src/Symfony/Component/Validator/Constraints/PasswordStrength.php index b41965879f5eb..816708d67ea91 100644 --- a/src/Symfony/Component/Validator/Constraints/PasswordStrength.php +++ b/src/Symfony/Component/Validator/Constraints/PasswordStrength.php @@ -40,13 +40,14 @@ final class PasswordStrength extends Constraint public int $minScore; - public function __construct(array $options = null, int $minScore = null, array $groups = null, mixed $payload = null) + public function __construct(array $options = null, int $minScore = null, array $groups = null, mixed $payload = null, string $message = null) { $options['minScore'] ??= self::STRENGTH_MEDIUM; parent::__construct($options, $groups, $payload); $this->minScore = $minScore ?? $this->minScore; + $this->message = $message ?? $this->message; if ($this->minScore < 1 || 4 < $this->minScore) { throw new ConstraintDefinitionException(sprintf('The parameter "minScore" of the "%s" constraint must be an integer between 1 and 4.', self::class)); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthTest.php b/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthTest.php index 2cfe6a3abb697..713c30deec7cf 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthTest.php @@ -25,9 +25,10 @@ public function testConstructor() public function testConstructorWithParameters() { - $constraint = new PasswordStrength(minScore: PasswordStrength::STRENGTH_STRONG); + $constraint = new PasswordStrength(minScore: PasswordStrength::STRENGTH_STRONG, message: 'This password should be strong.'); $this->assertSame(PasswordStrength::STRENGTH_STRONG, $constraint->minScore); + $this->assertSame('This password should be strong.', $constraint->message); } public function testInvalidScoreOfZero() diff --git a/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorTest.php index 474dd889c3686..21dabcad738a4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorTest.php @@ -77,5 +77,11 @@ public static function provideInvalidConstraints(): iterable 'The password strength is too low. Please use a stronger password.', PasswordStrength::PASSWORD_STRENGTH_ERROR, ]; + yield [ + new PasswordStrength(message: 'This password should be strong.'), + 'password', + 'This password should be strong.', + PasswordStrength::PASSWORD_STRENGTH_ERROR, + ]; } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: