vendor/symfony/password-hasher/Hasher/UserPasswordHasher.php line 33

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\PasswordHasher\Hasher;
  11. use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  13. /**
  14.  * Hashes passwords based on the user and the PasswordHasherFactory.
  15.  *
  16.  * @author Ariel Ferrandini <arielferrandini@gmail.com>
  17.  *
  18.  * @final
  19.  */
  20. class UserPasswordHasher implements UserPasswordHasherInterface
  21. {
  22.     private $hasherFactory;
  23.     public function __construct(PasswordHasherFactoryInterface $hasherFactory)
  24.     {
  25.         $this->hasherFactory $hasherFactory;
  26.     }
  27.     public function hashPassword(PasswordAuthenticatedUserInterface $userstring $plainPassword): string
  28.     {
  29.         $salt null;
  30.         if ($user instanceof LegacyPasswordAuthenticatedUserInterface) {
  31.             $salt $user->getSalt();
  32.         }
  33.         $hasher $this->hasherFactory->getPasswordHasher($user);
  34.         return $hasher->hash($plainPassword$salt);
  35.     }
  36.     public function isPasswordValid(PasswordAuthenticatedUserInterface $userstring $plainPassword): bool
  37.     {
  38.         $salt null;
  39.         if ($user instanceof LegacyPasswordAuthenticatedUserInterface) {
  40.             $salt $user->getSalt();
  41.         }
  42.         if (null === $user->getPassword()) {
  43.             return false;
  44.         }
  45.         $hasher $this->hasherFactory->getPasswordHasher($user);
  46.         return $hasher->verify($user->getPassword(), $plainPassword$salt);
  47.     }
  48.     public function needsRehash(PasswordAuthenticatedUserInterface $user): bool
  49.     {
  50.         if (null === $user->getPassword()) {
  51.             return false;
  52.         }
  53.         $hasher $this->hasherFactory->getPasswordHasher($user);
  54.         return $hasher->needsRehash($user->getPassword());
  55.     }
  56. }