Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement IPasswordHashBackend #1194

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
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
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" />
Pytal marked this conversation as resolved.
Show resolved Hide resolved
</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
Loading