]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat: Allow getting/setting the password hash of a user
authorChristopher Ng <chrng8@gmail.com>
Tue, 25 Jun 2024 22:47:50 +0000 (15:47 -0700)
committerChristopher Ng <chrng8@gmail.com>
Mon, 8 Jul 2024 23:30:52 +0000 (16:30 -0700)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
lib/private/User/LazyUser.php
lib/private/User/User.php
lib/public/IUser.php

index 80b2bfe510f89178c6a6bc24ef056ca084623008..cd3e268be48bc31479943234822e0693248009aa 100644 (file)
@@ -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();
        }
index 644d3e27f881e05317b0d036505fc1c49f3317d0..6495b5cf2761c9171edc82f5b4d0e11901a3fa38 100644 (file)
@@ -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
         *
index 2ed2d0d87b2fa06f8c09e2afcd1b2caeca600359..b808e734b95fea5cd8908ddff4337165e871c5d6 100644 (file)
@@ -76,6 +76,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
         *