Skip to content

Commit 22d2538

Browse files
authored
Avoid regenerating the remember me token if it is still fresh
1 parent afa31e5 commit 22d2538

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

RememberMe/PersistentRememberMeHandler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,12 @@ public function processRememberMe(RememberMeDetails $rememberMeDetails, UserInte
7474
throw new AuthenticationException('The cookie has expired.');
7575
}
7676

77-
$tokenValue = base64_encode(random_bytes(64));
78-
$this->tokenProvider->updateToken($series, $this->generateHash($tokenValue), new \DateTime());
77+
// if a token was regenerated less than a minute ago, there is no need to regenerate it
78+
// if multiple concurrent requests reauthenticate a user we do not want to update the token several times
79+
if ($persistentToken->getLastUsed()->getTimestamp() + 60 < time()) {
80+
$tokenValue = base64_encode(random_bytes(64));
81+
$this->tokenProvider->updateToken($series, $this->generateHash($tokenValue), new \DateTime());
82+
}
7983

8084
$this->createCookie($rememberMeDetails->withValue($tokenValue));
8185
}

0 commit comments

Comments
 (0)