class PasswordStrength
Validates that the given password has reached a minimum strength.
@author Florent Morselli <florent.morselli@spomky-labs.com>
Hierarchy
- class \Symfony\Component\Validator\Constraint
- class \Symfony\Component\Validator\Constraints\PasswordStrength extends \Symfony\Component\Validator\Constraint
Expanded class hierarchy of PasswordStrength
File
-
vendor/
symfony/ validator/ Constraints/ PasswordStrength.php, line 22
Namespace
Symfony\Component\Validator\ConstraintsView source
final class PasswordStrength extends Constraint {
public const STRENGTH_VERY_WEAK = 0;
public const STRENGTH_WEAK = 1;
public const STRENGTH_MEDIUM = 2;
public const STRENGTH_STRONG = 3;
public const STRENGTH_VERY_STRONG = 4;
public const PASSWORD_STRENGTH_ERROR = '4234df00-45dd-49a4-b303-a75dbf8b10d8';
protected const ERROR_NAMES = [
self::PASSWORD_STRENGTH_ERROR => 'PASSWORD_STRENGTH_ERROR',
];
public string $message = 'The password strength is too low. Please use a stronger password.';
public int $minScore;
/**
* @param array<string,mixed>|null $options
* @param self::STRENGTH_*|null $minScore The minimum required strength of the password (defaults to {@see PasswordStrength::STRENGTH_MEDIUM})
* @param string[]|null $groups
*/
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));
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Constraint::$groups | public | property | The groups that the constraint belongs to. | ||
Constraint::$payload | public | property | Domain-specific data attached to a constraint. | ||
Constraint::addImplicitGroupName | public | function | Adds the given group if this constraint is in the Default group. | 2 | |
Constraint::CLASS_CONSTRAINT | public | constant | Marks a constraint that can be put onto classes. | ||
Constraint::DEFAULT_GROUP | public | constant | The name of the group given to all constraints with no explicit group. | ||
Constraint::getDefaultOption | public | function | Returns the name of the default option. | 28 | |
Constraint::getErrorName | public static | function | Returns the name of the given error code. | ||
Constraint::getRequiredOptions | public | function | Returns the name of the required options. | 22 | |
Constraint::getTargets | public | function | Returns whether the constraint can be put onto classes, properties or both. |
8 | |
Constraint::normalizeOptions | protected | function | |||
Constraint::PROPERTY_CONSTRAINT | public | constant | Marks a constraint that can be put onto properties. | ||
Constraint::validatedBy | public | function | Returns the name of the class that validates this constraint. | 9 | |
Constraint::__get | public | function | Returns the value of a lazily initialized option. | 2 | |
Constraint::__isset | public | function | 1 | ||
Constraint::__set | public | function | Sets the value of a lazily initialized option. | 1 | |
Constraint::__sleep | public | function | Optimizes the serialized value to minimize storage space. | ||
PasswordStrength::$message | public | property | |||
PasswordStrength::$minScore | public | property | |||
PasswordStrength::ERROR_NAMES | protected | constant | Maps error codes to the names of their constants. | Overrides Constraint::ERROR_NAMES | |
PasswordStrength::PASSWORD_STRENGTH_ERROR | public | constant | |||
PasswordStrength::STRENGTH_MEDIUM | public | constant | |||
PasswordStrength::STRENGTH_STRONG | public | constant | |||
PasswordStrength::STRENGTH_VERY_STRONG | public | constant | |||
PasswordStrength::STRENGTH_VERY_WEAK | public | constant | |||
PasswordStrength::STRENGTH_WEAK | public | constant | |||
PasswordStrength::__construct | public | function | Overrides Constraint::__construct |