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 | 34d97d45cfae8a4f82bedb54582c1fc8eaf41369 (patch) | |
tree | d5631061447d94ba8d8233d22d820fe75f1a2060 | |
parent | a330f4c9d558a089bfa389a3227ef0e3c43816d1 (diff) | |
download | nextcloud-server-34d97d45cfae8a4f82bedb54582c1fc8eaf41369.tar.gz nextcloud-server-34d97d45cfae8a4f82bedb54582c1fc8eaf41369.zip |
feat: Allow getting/setting the password hash of a user
Signed-off-by: Christopher Ng <chrng8@gmail.com>
-rw-r--r-- | lib/private/User/LazyUser.php | 8 | ||||
-rw-r--r-- | lib/private/User/User.php | 15 | ||||
-rw-r--r-- | lib/public/IUser.php | 14 |
3 files changed, 37 insertions, 0 deletions
diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php index 80b2bfe510f..cd3e268be48 100644 --- a/lib/private/User/LazyUser.php +++ b/lib/private/User/LazyUser.php @@ -73,6 +73,14 @@ class LazyUser implements IUser { return $this->getUser()->setPassword($password, $recoveryPassword); } + public function getPasswordHash(): ?string { + return $this->getUser()->getPasswordHash(); + } + + public function setPasswordHash(string $passwordHash): bool { + return $this->getUser()->setPasswordHash($passwordHash); + } + public function getHome() { return $this->getUser()->getHome(); } diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 644d3e27f88..6495b5cf276 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -25,6 +25,7 @@ use OCP\IUser; use OCP\IUserBackend; use OCP\Notification\IManager as INotificationManager; use OCP\User\Backend\IGetHomeBackend; +use OCP\User\Backend\IPasswordHashBackend; use OCP\User\Backend\IProvideAvatarBackend; use OCP\User\Backend\IProvideEnabledStateBackend; use OCP\User\Backend\ISetDisplayNameBackend; @@ -319,6 +320,20 @@ class User implements IUser { } } + public function getPasswordHash(): ?string { + if (!($this->backend instanceof IPasswordHashBackend)) { + return null; + } + return $this->backend->getPasswordHash($this->uid); + } + + public function setPasswordHash(string $passwordHash): bool { + if (!($this->backend instanceof IPasswordHashBackend)) { + return false; + } + return $this->backend->setPasswordHash($this->uid, $passwordHash); + } + /** * get the users home folder to mount * diff --git a/lib/public/IUser.php b/lib/public/IUser.php index 2ed2d0d87b2..b808e734b95 100644 --- a/lib/public/IUser.php +++ b/lib/public/IUser.php @@ -77,6 +77,20 @@ interface IUser { public function setPassword($password, $recoveryPassword = null); /** + * Get the password hash of the user + * + * @since 30.0.0 + */ + public function getPasswordHash(): ?string; + + /** + * Set the password hash of the user + * + * @since 30.0.0 + */ + public function setPasswordHash(string $passwordHash): bool; + + /** * get the users home folder to mount * * @return string |