]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add a const for the max user password length 35981/head
authorJoas Schilling <coding@schilljs.com>
Wed, 4 Jan 2023 10:23:43 +0000 (11:23 +0100)
committerJoas Schilling <coding@schilljs.com>
Wed, 4 Jan 2023 10:23:43 +0000 (11:23 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/provisioning_api/lib/Controller/UsersController.php
apps/settings/lib/Controller/ChangePasswordController.php
core/Controller/LostController.php
lib/private/Authentication/Token/PublicKeyTokenProvider.php
lib/public/IUserManager.php

index 434912f32aa72593be7f7ab283cbb6300a304de8..97d66acd2e0bba98fb2af247ffd235a514153867 100644 (file)
@@ -389,7 +389,7 @@ class UsersController extends AUserData {
                }
 
                $generatePasswordResetToken = false;
-               if (strlen($password) > 469) {
+               if (strlen($password) > IUserManager::MAX_PASSWORD_LENGTH) {
                        throw new OCSException('Invalid password value', 101);
                }
                if ($password === '') {
@@ -889,7 +889,7 @@ class UsersController extends AUserData {
                                break;
                        case self::USER_FIELD_PASSWORD:
                                try {
-                                       if (strlen($value) > 469) {
+                                       if (strlen($value) > IUserManager::MAX_PASSWORD_LENGTH) {
                                                throw new OCSException('Invalid password value', 102);
                                        }
                                        if (!$targetUser->canChangePassword()) {
index a25f0b0e59bf72c751bbbb409473836c4b42e292..20ec28220a5a87c67a11f1f3cff3732a8b4d1766 100644 (file)
@@ -95,7 +95,7 @@ class ChangePasswordController extends Controller {
                }
 
                try {
-                       if ($newpassword === null || strlen($newpassword) > 469 || $user->setPassword($newpassword) === false) {
+                       if ($newpassword === null || strlen($newpassword) > IUserManager::MAX_PASSWORD_LENGTH || $user->setPassword($newpassword) === false) {
                                return new JSONResponse([
                                        'status' => 'error',
                                        'data' => [
@@ -146,7 +146,7 @@ class ChangePasswordController extends Controller {
                        ]);
                }
 
-               if (strlen($password) > 469) {
+               if (strlen($password) > IUserManager::MAX_PASSWORD_LENGTH) {
                        return new JSONResponse([
                                'status' => 'error',
                                'data' => [
index e7960dbcef5824acd347a7de8ca834b3f740b65c..6176e3cd5e58ee64d22099e48a283bd2e06d6185 100644 (file)
@@ -240,7 +240,7 @@ class LostController extends Controller {
                        $this->eventDispatcher->dispatchTyped(new BeforePasswordResetEvent($user, $password));
                        \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]);
 
-                       if (strlen($password) > 469) {
+                       if (strlen($password) > IUserManager::MAX_PASSWORD_LENGTH) {
                                throw new HintException('Password too long', $this->l10n->t('Password is too long. Maximum allowed length is 469 characters.'));
                        }
 
index c7e295683831df962a079b14ad9d0ca51e000f20..d00d3e415399ecbb12bbbd939288cd93aea2fc93 100644 (file)
@@ -40,6 +40,7 @@ use OCP\AppFramework\Db\DoesNotExistException;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\IConfig;
 use OCP\IDBConnection;
+use OCP\IUserManager;
 use OCP\Security\ICrypto;
 use Psr\Log\LoggerInterface;
 
@@ -397,7 +398,7 @@ class PublicKeyTokenProvider implements IProvider {
                $dbToken->setPrivateKey($this->encrypt($privateKey, $token));
 
                if (!is_null($password) && $this->config->getSystemValueBool('auth.storeCryptedPassword', true)) {
-                       if (strlen($password) > 469) {
+                       if (strlen($password) > IUserManager::MAX_PASSWORD_LENGTH) {
                                throw new \RuntimeException('Trying to save a password with more than 469 characters is not supported. If you want to use big passwords, disable the auth.storeCryptedPassword option in config.php');
                        }
                        $dbToken->setPassword($this->encryptPassword($password, $publicKey));
index 8caa027468bb39d4520c6ced3ef8a610db36b40f..151c153917f6dee3f924fbb0d43bedbb9d2833ac 100644 (file)
@@ -46,6 +46,12 @@ namespace OCP;
  * @since 8.0.0
  */
 interface IUserManager {
+
+       /**
+        * @since 26.0.0
+        */
+       public const MAX_PASSWORD_LENGTH = 469;
+
        /**
         * register a user backend
         *