vendor/symfony/security-http/Authenticator/Passport/Badge/PasswordUpgradeBadge.php line 26

Open in your IDE?
  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\Http\Authenticator\Passport\Badge;
  11. use Symfony\Component\Security\Core\Exception\LogicException;
  12. use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
  13. /**
  14.  * Adds automatic password migration, if enabled and required in the password encoder.
  15.  *
  16.  * @see PasswordUpgraderInterface
  17.  *
  18.  * @author Wouter de Jong <wouter@wouterj.nl>
  19.  *
  20.  * @final
  21.  */
  22. class PasswordUpgradeBadge implements BadgeInterface
  23. {
  24.     private ?string $plaintextPassword null;
  25.     private ?PasswordUpgraderInterface $passwordUpgrader;
  26.     /**
  27.      * @param string                         $plaintextPassword The presented password, used in the rehash
  28.      * @param PasswordUpgraderInterface|null $passwordUpgrader  The password upgrader, defaults to the UserProvider if null
  29.      */
  30.     public function __construct(string $plaintextPasswordPasswordUpgraderInterface $passwordUpgrader null)
  31.     {
  32.         $this->plaintextPassword $plaintextPassword;
  33.         $this->passwordUpgrader $passwordUpgrader;
  34.     }
  35.     public function getAndErasePlaintextPassword(): string
  36.     {
  37.         $password $this->plaintextPassword;
  38.         if (null === $password) {
  39.             throw new LogicException('The password is erased as another listener already used this badge.');
  40.         }
  41.         $this->plaintextPassword null;
  42.         return $password;
  43.     }
  44.     public function getPasswordUpgrader(): ?PasswordUpgraderInterface
  45.     {
  46.         return $this->passwordUpgrader;
  47.     }
  48.     public function isResolved(): bool
  49.     {
  50.         return true;
  51.     }
  52. }