mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat: Implement IPasswordHashBackend in database user backend
Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
parent
69f252a90d
commit
a330f4c9d5
1 changed files with 31 additions and 1 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue