Skip to content
Merged
Changes from all commits
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
31 changes: 13 additions & 18 deletions lib/private/User/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ public function setPassword(string $uid, string $password): bool {
$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;
Expand Down Expand Up @@ -329,28 +335,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 +369,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 +385,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