Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /home/pastorz/old-espace-client/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

vendor/symfonycasts/reset-password-bundle/src/Generator/ResetPasswordTokenGenerator.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the SymfonyCasts ResetPasswordBundle package.
  4.  * Copyright (c) SymfonyCasts <https://symfonycasts.com/>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace SymfonyCasts\Bundle\ResetPassword\Generator;
  9. use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordTokenComponents;
  10. /**
  11.  * @author Jesse Rushlow <jr@rushlow.dev>
  12.  * @author Ryan Weaver   <ryan@symfonycasts.com>
  13.  *
  14.  * @internal
  15.  *
  16.  * @final
  17.  */
  18. class ResetPasswordTokenGenerator
  19. {
  20.     /**
  21.      * @var string Unique, random, cryptographically secure string
  22.      */
  23.     private $signingKey;
  24.     /**
  25.      * @var ResetPasswordRandomGenerator
  26.      */
  27.     private $randomGenerator;
  28.     public function __construct(string $signingKeyResetPasswordRandomGenerator $generator)
  29.     {
  30.         $this->signingKey $signingKey;
  31.         $this->randomGenerator $generator;
  32.     }
  33.     /**
  34.      * Get a cryptographically secure token with it's non-hashed components.
  35.      *
  36.      * @param mixed  $userId   Unique user identifier
  37.      * @param string $verifier Only required for token comparison
  38.      */
  39.     public function createToken(\DateTimeInterface $expiresAt$userIdstring $verifier null): ResetPasswordTokenComponents
  40.     {
  41.         if (null === $verifier) {
  42.             $verifier $this->randomGenerator->getRandomAlphaNumStr();
  43.         }
  44.         $selector $this->randomGenerator->getRandomAlphaNumStr();
  45.         $encodedData json_encode([$verifier$userId$expiresAt->getTimestamp()]);
  46.         return new ResetPasswordTokenComponents(
  47.             $selector,
  48.             $verifier,
  49.             $this->getHashedToken($encodedData)
  50.         );
  51.     }
  52.     private function getHashedToken(string $data): string
  53.     {
  54.         return base64_encode(hash_hmac('sha256'$data$this->signingKeytrue));
  55.     }
  56. }