Skip to content

Commit 2fb4dac

Browse files
committed
fix(authentication): Update the token when the hash is null or can not be verified
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 28b18d5 commit 2fb4dac

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

lib/private/Authentication/Token/PublicKeyTokenProvider.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,28 @@ public function updatePasswords(string $uid, string $password) {
448448
// Update the password for all tokens
449449
$tokens = $this->mapper->getTokenByUser($uid);
450450
$newPasswordHash = null;
451-
$verifiedHashes = [];
451+
452+
/**
453+
* - true: The password hash could not be verified anymore
454+
* and the token needs to be updated with the newly encrypted password
455+
* - false: The hash could still be verified
456+
* - missing: The hash needs to be verified
457+
*/
458+
$hashNeedsUpdate = [];
459+
452460
foreach ($tokens as $t) {
453-
if ($t->getPasswordHash() === null || !isset($verifiedHashes[$t->getPasswordHash()]) || !$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
461+
if (!isset($hashNeedsUpdate[$t->getPasswordHash()])) {
462+
if ($t->getPasswordHash() === null) {
463+
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
464+
} elseif (!$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
465+
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
466+
} else {
467+
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = false;
468+
}
469+
}
470+
$needsUpdating = $hashNeedsUpdate[$t->getPasswordHash() ?: ''] ?? true;
471+
472+
if ($needsUpdating) {
454473
if ($newPasswordHash === null) {
455474
$newPasswordHash = $this->hashPassword($password);
456475
}
@@ -460,8 +479,6 @@ public function updatePasswords(string $uid, string $password) {
460479
$t->setPasswordHash($newPasswordHash);
461480
$t->setPasswordInvalid(false);
462481
$this->updateToken($t);
463-
} else {
464-
$verifiedHashes[$t->getPasswordHash() ?: ''] = true;
465482
}
466483
}
467484
}

0 commit comments

Comments
 (0)