TooManyLoginAttemptsAuthenticationException.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Security\Core\Exception;
  11. /**
  12. * This exception is thrown if there where too many failed login attempts in
  13. * this session.
  14. *
  15. * @author Wouter de Jong <wouter@wouterj.nl>
  16. */
  17. class TooManyLoginAttemptsAuthenticationException extends AuthenticationException
  18. {
  19. private $threshold;
  20. public function __construct(int $threshold = null)
  21. {
  22. $this->threshold = $threshold;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function getMessageData(): array
  28. {
  29. return [
  30. '%minutes%' => $this->threshold,
  31. ];
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function getMessageKey(): string
  37. {
  38. return 'Too many failed login attempts, please try again '.($this->threshold ? 'in %minutes% minute'.($this->threshold > 1 ? 's' : '').'.' : 'later.');
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function __serialize(): array
  44. {
  45. return [$this->threshold, parent::__serialize()];
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function __unserialize(array $data): void
  51. {
  52. [$this->threshold, $parentData] = $data;
  53. $parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
  54. parent::__unserialize($parentData);
  55. }
  56. }