Skip to content

Commit

Permalink
feat: Implement IPasswordHashBackend
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Jun 28, 2024
1 parent aa23b0a commit 7f329da
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\User\Backend\IGetDisplayNameBackend;
use OCP\User\Backend\IGetHomeBackend;
use OCP\User\Backend\IGetRealUIDBackend;
use OCP\User\Backend\IPasswordHashBackend;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;

Expand All @@ -47,7 +48,8 @@ class UserBackend extends ABackend implements
ICheckPasswordBackend,
IGetHomeBackend,
ICountUsersBackend,
IGetRealUIDBackend {
IGetRealUIDBackend,
IPasswordHashBackend {
/** @var CappedMemoryCache */
private $cache;
/** @var IEventDispatcher */
Expand Down Expand Up @@ -160,6 +162,31 @@ public function setPassword(string $uid, string $password): bool {
return false;
}

public function getPasswordHash(string $userId): ?string {
if (!$this->userExists($userId)) {
return null;
}
$qb = $this->dbConn->getQueryBuilder();
$qb->select('password')
->from('guests_users')
->where($qb->expr()->eq('uid_lower', $qb->createNamedParameter(mb_strtolower($userId))));
/** @var false|string $hash */
$hash = $qb->executeQuery()->fetchOne();
if ($hash === false) {
return null;
}
return $hash;
}

public function setPasswordHash(string $userId, string $passwordHash): bool {
$qb = $this->dbConn->getQueryBuilder();
$qb->update('guests_users')
->set('password', $qb->createNamedParameter($passwordHash))
->where($qb->expr()->eq('uid_lower', $qb->createNamedParameter(mb_strtolower($userId))));
$result = $qb->executeStatement();
return ($result !== 0);
}

/**
* Set display name
*
Expand Down

0 comments on commit 7f329da

Please sign in to comment.