diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2022-03-02 11:41:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-02 11:41:32 +0100 |
commit | 18bafefb00add3a7e075e58c1edb420c27a61a24 (patch) | |
tree | 6efad5d6592a05677e7cba69a4f85cd2c3278a58 /lib/private/User | |
parent | 5bc2a6a37e4832c46ac94b23dd15c7e45bbefe37 (diff) | |
parent | 25caf4a42c7e3a705137e997627249ef71665b53 (diff) | |
download | nextcloud-server-18bafefb00add3a7e075e58c1edb420c27a61a24.tar.gz nextcloud-server-18bafefb00add3a7e075e58c1edb420c27a61a24.zip |
Merge pull request #31218 from nextcloud/techdebt/noid/use-cache-also-for-userbackend-getpassword
Use the cache also for UserBackend::getPassword
Diffstat (limited to 'lib/private/User')
-rw-r--r-- | lib/private/User/Database.php | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index 81094d4d8af..a9464c27085 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -193,7 +193,13 @@ class Database extends ABackend implements $hasher = \OC::$server->getHasher(); $hashedPassword = $hasher->hash($password); - return $this->updatePassword($uid, $hashedPassword); + $return = $this->updatePassword($uid, $hashedPassword); + + if ($return) { + $this->cache[$uid]['password'] = $hashedPassword; + } + + return $return; } return false; @@ -329,28 +335,16 @@ class Database extends ABackend implements * returns the user id or false */ public function checkPassword(string $loginName, string $password) { - $this->fixDI(); + $found = $this->loadUser($loginName); - $qb = $this->dbConn->getQueryBuilder(); - $qb->select('uid', 'password') - ->from($this->table) - ->where( - $qb->expr()->eq( - 'uid_lower', $qb->createNamedParameter(mb_strtolower($loginName)) - ) - ); - $result = $qb->execute(); - $row = $result->fetch(); - $result->closeCursor(); - - if ($row) { - $storedHash = $row['password']; + if ($found && is_array($this->cache[$loginName])) { + $storedHash = $this->cache[$loginName]['password']; $newHash = ''; if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) { if (!empty($newHash)) { $this->updatePassword($loginName, $newHash); } - return (string)$row['uid']; + return (string)$this->cache[$loginName]['uid']; } } @@ -375,7 +369,7 @@ class Database extends ABackend implements } $qb = $this->dbConn->getQueryBuilder(); - $qb->select('uid', 'displayname') + $qb->select('uid', 'displayname', 'password') ->from($this->table) ->where( $qb->expr()->eq( @@ -391,6 +385,7 @@ class Database extends ABackend implements $this->cache[$uid] = [ 'uid' => (string)$row['uid'], 'displayname' => (string)$row['displayname'], + 'password' => (string)$row['password'], ]; } else { $this->cache[$uid] = false; |