Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use the cache also for UserBackend::getPassword
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Feb 16, 2022
commit 23ef02fbe2b95a3be6eb21c8864bcbbef8d4a228
23 changes: 6 additions & 17 deletions lib/private/User/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,28 +329,16 @@ public function searchKnownUsersByDisplayName(string $searcher, string $pattern,
* 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'];
}
}

Expand All @@ -375,7 +363,7 @@ private function loadUser($uid) {
}

$qb = $this->dbConn->getQueryBuilder();
$qb->select('uid', 'displayname')
$qb->select('uid', 'displayname', 'password')
->from($this->table)
->where(
$qb->expr()->eq(
Expand All @@ -391,6 +379,7 @@ private function loadUser($uid) {
$this->cache[$uid] = [
'uid' => (string)$row['uid'],
'displayname' => (string)$row['displayname'],
'password' => (string)$row['password'],
];
} else {
$this->cache[$uid] = false;
Expand Down