diff options
author | Christopher Ng <chrng8@gmail.com> | 2024-06-25 15:47:50 -0700 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2024-07-08 16:30:52 -0700 |
commit | a330f4c9d558a089bfa389a3227ef0e3c43816d1 (patch) | |
tree | adf39470d5b31b471a99c8e4a633a6a3d67b0d56 /lib/private | |
parent | 69f252a90d6666d5dc55fd46fcc5698da0cec164 (diff) | |
download | nextcloud-server-a330f4c9d558a089bfa389a3227ef0e3c43816d1.tar.gz nextcloud-server-a330f4c9d558a089bfa389a3227ef0e3c43816d1.zip |
feat: Implement IPasswordHashBackend in database user backend
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/User/Database.php | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index cc7050f2da8..0a0231a7784 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -21,6 +21,7 @@ use OCP\User\Backend\ICreateUserBackend; use OCP\User\Backend\IGetDisplayNameBackend; use OCP\User\Backend\IGetHomeBackend; use OCP\User\Backend\IGetRealUIDBackend; +use OCP\User\Backend\IPasswordHashBackend; use OCP\User\Backend\ISearchKnownUsersBackend; use OCP\User\Backend\ISetDisplayNameBackend; use OCP\User\Backend\ISetPasswordBackend; @@ -37,7 +38,8 @@ class Database extends ABackend implements IGetHomeBackend, ICountUsersBackend, ISearchKnownUsersBackend, - IGetRealUIDBackend { + IGetRealUIDBackend, + IPasswordHashBackend { /** @var CappedMemoryCache */ private $cache; @@ -176,6 +178,34 @@ class Database extends ABackend implements return false; } + public function getPasswordHash(string $userId): ?string { + $this->fixDI(); + if (!$this->userExists($userId)) { + return null; + } + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('password') + ->from($this->table) + ->where($qb->expr()->eq('uid_lower', $qb->createNamedParameter(mb_strtolower($userId)))); + /** @var false|string $hash */ + $hash = $qb->executeQuery()->fetchOne(); + if ($hash === false) { + return null; + } + $this->cache[$userId]['password'] = $hash; + return $hash; + } + + public function setPasswordHash(string $userId, string $passwordHash): bool { + $this->fixDI(); + $result = $this->updatePassword($userId, $passwordHash); + if (!$result) { + return false; + } + $this->cache[$userId]['password'] = $passwordHash; + return true; + } + /** * Set display name * |