Skip to content

Commit

Permalink
Merge pull request #1194 from nextcloud/feat/password-hash-backend
Browse files Browse the repository at this point in the history
feat: Implement IPasswordHashBackend
  • Loading branch information
Pytal authored Jul 11, 2024
2 parents f4e252b + 4166c63 commit 07f19a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Guests accounts can be created from the share menu by entering either the recipients email or name and choosing "create guest account", once the share is created the guest user will receive an email notification about the mail with a link to set their password.
Guests users can only access files shared to them and cannot create any files outside of shares, additionally, the apps accessible to guest accounts are whitelisted.]]></description>
<version>3.2.0</version>
<version>4.0.0</version>
<licence>agpl</licence>
<author>Nextcloud</author>
<types>
Expand All @@ -26,7 +26,7 @@ Guests users can only access files shared to them and cannot create any files ou
<screenshot>https://github.com/raw/nextcloud/guests/master/screenshots/settings.png</screenshot>
<screenshot>https://github.com/raw/nextcloud/guests/master/screenshots/dropdown.png</screenshot>
<dependencies>
<nextcloud min-version="29" max-version="30" />
<nextcloud min-version="30" max-version="30" />
</dependencies>
<commands>
<command>OCA\Guests\Command\ListCommand</command>
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion lib/UserBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace OCA\Guests;

use InvalidArgumentException;
use OC\Cache\CappedMemoryCache;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
Expand All @@ -34,6 +35,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 +49,8 @@ class UserBackend extends ABackend implements
ICheckPasswordBackend,
IGetHomeBackend,
ICountUsersBackend,
IGetRealUIDBackend {
IGetRealUIDBackend,
IPasswordHashBackend {
/** @var CappedMemoryCache */
private $cache;
/** @var IEventDispatcher */
Expand Down Expand Up @@ -160,6 +163,34 @@ 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 {
if (!$this->hasher->validate($passwordHash)) {
throw new InvalidArgumentException();
}
$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 07f19a6

Please sign in to comment.