mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-29 18:14:59 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -12,18 +12,7 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Security\PasswordRecover;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use UnexpectedValueException;
|
||||
|
||||
use function bin2hex;
|
||||
use function hash;
|
||||
use function hex2bin;
|
||||
use function random_bytes;
|
||||
use function strlen;
|
||||
use function trim;
|
||||
|
||||
class TokenManager
|
||||
{
|
||||
@@ -50,21 +39,21 @@ class TokenManager
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function generate(User $user, DateTimeInterface $expiration)
|
||||
public function generate(User $user, \DateTimeInterface $expiration)
|
||||
{
|
||||
$token = random_bytes(self::TOKEN_LENGTH);
|
||||
$token = \random_bytes(self::TOKEN_LENGTH);
|
||||
$username = $user->getUsernameCanonical();
|
||||
|
||||
if (empty($username)) {
|
||||
throw new UnexpectedValueException('username should not be empty to generate a token');
|
||||
throw new \UnexpectedValueException('username should not be empty to generate a token');
|
||||
}
|
||||
|
||||
$timestamp = (string) $expiration->getTimestamp();
|
||||
$hash = hash('sha1', $token . $username . $timestamp . $this->secret);
|
||||
$hash = \hash('sha1', $token.$username.$timestamp.$this->secret);
|
||||
|
||||
return [
|
||||
self::HASH => $hash,
|
||||
self::TOKEN => bin2hex($token),
|
||||
self::TOKEN => \bin2hex($token),
|
||||
self::TIMESTAMP => $timestamp,
|
||||
self::USERNAME_CANONICAL => $username,
|
||||
];
|
||||
@@ -72,23 +61,23 @@ class TokenManager
|
||||
|
||||
public function verify($hash, $token, User $user, string $timestamp)
|
||||
{
|
||||
$token = hex2bin(trim((string) $token));
|
||||
$token = \hex2bin(\trim((string) $token));
|
||||
|
||||
if (strlen($token) !== self::TOKEN_LENGTH) {
|
||||
if (self::TOKEN_LENGTH !== \strlen($token)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$username = $user->getUsernameCanonical();
|
||||
$date = DateTimeImmutable::createFromFormat('U', $timestamp);
|
||||
$date = \DateTimeImmutable::createFromFormat('U', $timestamp);
|
||||
|
||||
if ($date < new DateTime('now')) {
|
||||
if ($date < new \DateTime('now')) {
|
||||
$this->logger->info('receiving a password recover token with expired '
|
||||
. 'validity');
|
||||
.'validity');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$expected = hash('sha1', $token . $username . $timestamp . $this->secret);
|
||||
$expected = \hash('sha1', $token.$username.$timestamp.$this->secret);
|
||||
|
||||
if ($expected !== $hash) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user