fix(authentication): Only verify each hash once

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2023-01-09 14:53:12 +01:00
parent 3892c3edc9
commit 55d8aec759
No known key found for this signature in database
GPG key ID: 74434EFE0D2E2205

View file

@ -448,9 +448,11 @@ class PublicKeyTokenProvider implements IProvider {
// Update the password for all tokens
$tokens = $this->mapper->getTokenByUser($uid);
$passwordHash = $this->hashPassword($password);
$verifiedHashes = [];
foreach ($tokens as $t) {
$publicKey = $t->getPublicKey();
if ($t->getPasswordHash() === null || $this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
if ($t->getPasswordHash() === null || isset($verifiedHashes[$t->getPasswordHash()]) || $this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
$verifiedHashes[$t->getPasswordHash() ?: ''] = true;
$publicKey = $t->getPublicKey();
$t->setPassword($this->encryptPassword($password, $publicKey));
$t->setPasswordHash($passwordHash);
$t->setPasswordInvalid(false);