NotCompromisedPassword.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. /**
  13. * Checks if a password has been leaked in a data breach.
  14. *
  15. * @Annotation
  16. * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  17. *
  18. * @author Kévin Dunglas <dunglas@gmail.com>
  19. */
  20. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
  21. class NotCompromisedPassword extends Constraint
  22. {
  23. public const COMPROMISED_PASSWORD_ERROR = 'd9bcdbfe-a9d6-4bfa-a8ff-da5fd93e0f6d';
  24. protected static $errorNames = [self::COMPROMISED_PASSWORD_ERROR => 'COMPROMISED_PASSWORD_ERROR'];
  25. public $message = 'This password has been leaked in a data breach, it must not be used. Please use another password.';
  26. public $threshold = 1;
  27. public $skipOnError = false;
  28. public function __construct(
  29. array $options = null,
  30. string $message = null,
  31. int $threshold = null,
  32. bool $skipOnError = null,
  33. array $groups = null,
  34. $payload = null
  35. ) {
  36. parent::__construct($options, $groups, $payload);
  37. $this->message = $message ?? $this->message;
  38. $this->threshold = $threshold ?? $this->threshold;
  39. $this->skipOnError = $skipOnError ?? $this->skipOnError;
  40. }
  41. }