mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #36048 from nextcloud/bugfix/36046/only-verify-the-same-hash-once
fix(authentication): Only verify each hash once
This commit is contained in:
commit
fc096ae9db
1 changed files with 28 additions and 4 deletions
|
|
@ -447,12 +447,36 @@ class PublicKeyTokenProvider implements IProvider {
|
|||
|
||||
// Update the password for all tokens
|
||||
$tokens = $this->mapper->getTokenByUser($uid);
|
||||
$passwordHash = $this->hashPassword($password);
|
||||
$newPasswordHash = null;
|
||||
|
||||
/**
|
||||
* - true: The password hash could not be verified anymore
|
||||
* and the token needs to be updated with the newly encrypted password
|
||||
* - false: The hash could still be verified
|
||||
* - missing: The hash needs to be verified
|
||||
*/
|
||||
$hashNeedsUpdate = [];
|
||||
|
||||
foreach ($tokens as $t) {
|
||||
$publicKey = $t->getPublicKey();
|
||||
if ($t->getPasswordHash() === null || $this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
|
||||
if (!isset($hashNeedsUpdate[$t->getPasswordHash()])) {
|
||||
if ($t->getPasswordHash() === null) {
|
||||
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
|
||||
} elseif (!$this->hasher->verify(sha1($password) . $password, $t->getPasswordHash())) {
|
||||
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = true;
|
||||
} else {
|
||||
$hashNeedsUpdate[$t->getPasswordHash() ?: ''] = false;
|
||||
}
|
||||
}
|
||||
$needsUpdating = $hashNeedsUpdate[$t->getPasswordHash() ?: ''] ?? true;
|
||||
|
||||
if ($needsUpdating) {
|
||||
if ($newPasswordHash === null) {
|
||||
$newPasswordHash = $this->hashPassword($password);
|
||||
}
|
||||
|
||||
$publicKey = $t->getPublicKey();
|
||||
$t->setPassword($this->encryptPassword($password, $publicKey));
|
||||
$t->setPasswordHash($passwordHash);
|
||||
$t->setPasswordHash($newPasswordHash);
|
||||
$t->setPasswordInvalid(false);
|
||||
$this->updateToken($t);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue