vendor/symfony/security-core/Encoder/MigratingPasswordEncoder.php line 16

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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\Encoder;
  11. use Symfony\Component\PasswordHasher\Hasher\MigratingPasswordHasher;
  12. trigger_deprecation('symfony/security-core''5.3''The "%s" class is deprecated, use "%s" instead.'MigratingPasswordEncoder::class, MigratingPasswordHasher::class);
  13. /**
  14.  * Hashes passwords using the best available encoder.
  15.  * Validates them using a chain of encoders.
  16.  *
  17.  * /!\ Don't put a PlaintextPasswordEncoder in the list as that'd mean a leaked hash
  18.  * could be used to authenticate successfully without knowing the cleartext password.
  19.  *
  20.  * @author Nicolas Grekas <[email protected]>
  21.  *
  22.  * @deprecated since Symfony 5.3, use {@link MigratingPasswordHasher} instead
  23.  */
  24. final class MigratingPasswordEncoder extends BasePasswordEncoder implements SelfSaltingEncoderInterface
  25. {
  26.     private $bestEncoder;
  27.     private $extraEncoders;
  28.     public function __construct(PasswordEncoderInterface $bestEncoderPasswordEncoderInterface ...$extraEncoders)
  29.     {
  30.         $this->bestEncoder $bestEncoder;
  31.         $this->extraEncoders $extraEncoders;
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public function encodePassword(string $raw, ?string $salt): string
  37.     {
  38.         return $this->bestEncoder->encodePassword($raw$salt);
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function isPasswordValid(string $encodedstring $raw, ?string $salt): bool
  44.     {
  45.         if ($this->bestEncoder->isPasswordValid($encoded$raw$salt)) {
  46.             return true;
  47.         }
  48.         if (!$this->bestEncoder->needsRehash($encoded)) {
  49.             return false;
  50.         }
  51.         foreach ($this->extraEncoders as $encoder) {
  52.             if ($encoder->isPasswordValid($encoded$raw$salt)) {
  53.                 return true;
  54.             }
  55.         }
  56.         return false;
  57.     }
  58.     /**
  59.      * {@inheritdoc}
  60.      */
  61.     public function needsRehash(string $encoded): bool
  62.     {
  63.         return $this->bestEncoder->needsRehash($encoded);
  64.     }
  65. }