From 06eb6edeab56c59ec830ec8a19a728193c82acd6 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 3 Jun 2026 14:25:05 +0400 Subject: [PATCH] Rename password strength minimum field --- .../Auth/Validator/PasswordStrength.php | 8 ++--- .../Project/Http/Project/Policies/Get.php | 2 +- .../Policies/PasswordStrength/Update.php | 10 +++--- .../Project/Http/Project/Policies/XList.php | 2 +- .../Modules/Projects/Http/Projects/Create.php | 2 +- .../Response/Model/PolicyPasswordStrength.php | 2 +- tests/e2e/Services/Project/PoliciesBase.php | 36 +++++++++---------- ...oliciesPasswordStrengthIntegrationTest.php | 6 ++-- .../Project/ProjectConsoleClientTest.php | 2 +- .../Projects/ProjectsConsoleClientTest.php | 10 +++--- .../Auth/Validator/PasswordStrengthTest.php | 8 ++--- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Appwrite/Auth/Validator/PasswordStrength.php b/src/Appwrite/Auth/Validator/PasswordStrength.php index 46be71ad9e..a9772cbd22 100644 --- a/src/Appwrite/Auth/Validator/PasswordStrength.php +++ b/src/Appwrite/Auth/Validator/PasswordStrength.php @@ -9,7 +9,7 @@ namespace Appwrite\Auth\Validator; */ class PasswordStrength extends Password { - protected int $minLength; + protected int $min; protected bool $uppercase; protected bool $lowercase; protected bool $number; @@ -19,7 +19,7 @@ class PasswordStrength extends Password { parent::__construct($allowEmpty); - $this->minLength = $policy['minLength'] ?? 8; + $this->min = $policy['min'] ?? 8; $this->uppercase = $policy['uppercase'] ?? false; $this->lowercase = $policy['lowercase'] ?? false; $this->number = $policy['number'] ?? false; @@ -29,7 +29,7 @@ class PasswordStrength extends Password public function getDescription(): string { $requirements = [ - 'between ' . $this->minLength . ' and 256 characters long', + 'between ' . $this->min . ' and 256 characters long', ]; if ($this->uppercase) { @@ -64,7 +64,7 @@ class PasswordStrength extends Password return true; } - if (\strlen($value) < $this->minLength) { + if (\strlen($value) < $this->min) { return false; } diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php index b2c64a5a2b..feb1c1f263 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/Get.php @@ -112,7 +112,7 @@ class Get extends Action ], 'password-strength' => [ new Document(\array_merge([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php index 9580b83ce1..3fbcbe8b30 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/PasswordStrength/Update.php @@ -50,7 +50,7 @@ class Update extends Action ), ], )) - ->param('minLength', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) + ->param('min', null, new Range(8, 256), 'Minimum password length. Value must be between 8 and 256. Default is 8.', optional: true) ->param('uppercase', null, new Boolean(), 'Whether passwords must include at least one uppercase letter.', optional: true) ->param('lowercase', null, new Boolean(), 'Whether passwords must include at least one lowercase letter.', optional: true) ->param('number', null, new Boolean(), 'Whether passwords must include at least one number.', optional: true) @@ -64,7 +64,7 @@ class Update extends Action } public function action( - ?int $minLength, + ?int $min, ?bool $uppercase, ?bool $lowercase, ?bool $number, @@ -77,15 +77,15 @@ class Update extends Action ): void { $auths = $project->getAttribute('auths', []); $auths['passwordStrength'] = \array_merge([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, 'symbols' => false, ], $auths['passwordStrength'] ?? []); - if ($minLength !== null) { - $auths['passwordStrength']['minLength'] = $minLength; + if ($min !== null) { + $auths['passwordStrength']['min'] = $min; } if ($uppercase !== null) { $auths['passwordStrength']['uppercase'] = $uppercase; diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php index 5c69b3caac..0c74b86547 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Policies/XList.php @@ -104,7 +104,7 @@ class XList extends Action 'total' => $auths['passwordHistory'] ?? 0, ]), new Document(\array_merge([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php index 92a19e0ca1..1560788d09 100644 --- a/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php +++ b/src/Appwrite/Platform/Modules/Projects/Http/Projects/Create.php @@ -84,7 +84,7 @@ class Create extends Action 'limit' => 0, 'maxSessions' => 0, 'passwordStrength' => [ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php index 29a698f703..2a56cfa7e9 100644 --- a/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php +++ b/src/Appwrite/Utopia/Response/Model/PolicyPasswordStrength.php @@ -15,7 +15,7 @@ class PolicyPasswordStrength extends PolicyBase parent::__construct(); $this - ->addRule('minLength', [ + ->addRule('min', [ 'type' => self::TYPE_INTEGER, 'description' => 'Minimum password length required for user passwords.', 'default' => 8, diff --git a/tests/e2e/Services/Project/PoliciesBase.php b/tests/e2e/Services/Project/PoliciesBase.php index 3a708b374b..e92335a61c 100644 --- a/tests/e2e/Services/Project/PoliciesBase.php +++ b/tests/e2e/Services/Project/PoliciesBase.php @@ -15,7 +15,7 @@ trait PoliciesBase return [ 'password-dictionary' => ['enabled'], 'password-history' => ['total'], - 'password-strength' => ['minLength', 'uppercase', 'lowercase', 'number', 'symbols'], + 'password-strength' => ['min', 'uppercase', 'lowercase', 'number', 'symbols'], 'password-personal-data' => ['enabled'], 'session-alert' => ['enabled'], 'session-duration' => ['duration'], @@ -68,7 +68,7 @@ trait PoliciesBase $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -96,7 +96,7 @@ trait PoliciesBase $this->assertSame(5, $passwordHistory['body']['total']); $this->assertSame(200, $passwordStrength['headers']['status-code']); - $this->assertSame(12, $passwordStrength['body']['minLength']); + $this->assertSame(12, $passwordStrength['body']['min']); $this->assertSame(true, $passwordStrength['body']['uppercase']); $this->assertSame(true, $passwordStrength['body']['lowercase']); $this->assertSame(true, $passwordStrength['body']['number']); @@ -198,7 +198,7 @@ trait PoliciesBase $this->updatePasswordDictionaryPolicy(true); $this->updatePasswordHistoryPolicy(5); $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -224,7 +224,7 @@ trait PoliciesBase $this->assertSame(true, $byId['password-dictionary']['enabled']); $this->assertSame(5, $byId['password-history']['total']); - $this->assertSame(12, $byId['password-strength']['minLength']); + $this->assertSame(12, $byId['password-strength']['min']); $this->assertSame(true, $byId['password-strength']['uppercase']); $this->assertSame(true, $byId['password-strength']['lowercase']); $this->assertSame(true, $byId['password-strength']['number']); @@ -472,7 +472,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicy(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -481,7 +481,7 @@ trait PoliciesBase $this->assertSame(200, $response['headers']['status-code']); $this->assertSame('password-strength', $response['body']['$id']); - $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(12, $response['body']['min']); $this->assertSame(true, $response['body']['uppercase']); $this->assertSame(true, $response['body']['lowercase']); $this->assertSame(true, $response['body']['number']); @@ -489,7 +489,7 @@ trait PoliciesBase $policy = $this->getPolicy('password-strength'); $this->assertSame(200, $policy['headers']['status-code']); - $this->assertSame(12, $policy['body']['minLength']); + $this->assertSame(12, $policy['body']['min']); $this->assertSame(true, $policy['body']['uppercase']); $this->assertSame(true, $policy['body']['lowercase']); $this->assertSame(true, $policy['body']['number']); @@ -502,7 +502,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyOptionPreservesOtherOptions(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -516,7 +516,7 @@ trait PoliciesBase ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(12, $response['body']['min']); $this->assertSame(true, $response['body']['uppercase']); $this->assertSame(false, $response['body']['lowercase']); $this->assertSame(true, $response['body']['number']); @@ -526,23 +526,23 @@ trait PoliciesBase $this->resetPasswordStrengthPolicy(); } - public function testUpdatePasswordStrengthPolicyMinLength(): void + public function testUpdatePasswordStrengthPolicyMin(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, + 'min' => 8, ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(8, $response['body']['minLength']); + $this->assertSame(8, $response['body']['min']); // Cleanup $this->resetPasswordStrengthPolicy(); } - public function testUpdatePasswordStrengthPolicyBelowMinLength(): void + public function testUpdatePasswordStrengthPolicyBelowMin(): void { $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), [ - 'minLength' => 7, + 'min' => 7, ]); $this->assertSame(400, $response['headers']['status-code']); @@ -555,7 +555,7 @@ trait PoliciesBase $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $this->buildHeaders(), []); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(8, $response['body']['minLength']); + $this->assertSame(8, $response['body']['min']); $this->assertSame(false, $response['body']['uppercase']); $this->assertSame(false, $response['body']['lowercase']); $this->assertSame(false, $response['body']['number']); @@ -565,7 +565,7 @@ trait PoliciesBase public function testUpdatePasswordStrengthPolicyWithoutAuth(): void { $response = $this->updatePasswordStrengthPolicy([ - 'minLength' => 12, + 'min' => 12, ], false); $this->assertSame(401, $response['headers']['status-code']); @@ -1291,7 +1291,7 @@ trait PoliciesBase protected function resetPasswordStrengthPolicy(): void { $this->updatePasswordStrengthPolicy([ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php b/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php index 6a005a5a9c..4a8d132e2f 100644 --- a/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php +++ b/tests/e2e/Services/Project/PoliciesPasswordStrengthIntegrationTest.php @@ -32,7 +32,7 @@ class PoliciesPasswordStrengthIntegrationTest extends Scope ]; $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $serverHeaders, [ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -40,7 +40,7 @@ class PoliciesPasswordStrengthIntegrationTest extends Scope ]); $this->assertSame(200, $response['headers']['status-code']); - $this->assertSame(12, $response['body']['minLength']); + $this->assertSame(12, $response['body']['min']); $this->assertTrue($response['body']['uppercase']); $this->assertTrue($response['body']['lowercase']); $this->assertTrue($response['body']['number']); @@ -65,7 +65,7 @@ class PoliciesPasswordStrengthIntegrationTest extends Scope $this->assertSame(201, $valid['headers']['status-code']); $response = $this->client->call(Client::METHOD_PATCH, '/project/policies/password-strength', $serverHeaders, [ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, diff --git a/tests/e2e/Services/Project/ProjectConsoleClientTest.php b/tests/e2e/Services/Project/ProjectConsoleClientTest.php index f2ae8ef904..8fecd23823 100644 --- a/tests/e2e/Services/Project/ProjectConsoleClientTest.php +++ b/tests/e2e/Services/Project/ProjectConsoleClientTest.php @@ -122,7 +122,7 @@ class ProjectConsoleClientTest extends Scope $this->assertArrayNotHasKey('authLimit', $response['body']); $this->assertArrayNotHasKey('authSessionsLimit', $response['body']); $this->assertArrayNotHasKey('authPasswordHistory', $response['body']); - $this->assertArrayNotHasKey('authPasswordStrengthMinLength', $response['body']); + $this->assertArrayNotHasKey('authPasswordStrengthMin', $response['body']); $this->assertArrayNotHasKey('authPasswordStrengthRequireUppercase', $response['body']); $this->assertArrayNotHasKey('authPasswordStrengthRequireLowercase', $response['body']); $this->assertArrayNotHasKey('authPasswordStrengthRequireNumber', $response['body']); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 171f8f4465..94eb483f29 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2916,7 +2916,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 7, + 'min' => 7, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -2926,7 +2926,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 12, + 'min' => 12, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -2943,7 +2943,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(12, $response['body']['minLength']); + $this->assertEquals(12, $response['body']['min']); $this->assertEquals(true, $response['body']['uppercase']); $this->assertEquals(true, $response['body']['lowercase']); $this->assertEquals(true, $response['body']['number']); @@ -3062,7 +3062,7 @@ class ProjectsConsoleClientTest extends Scope 'x-appwrite-project' => $id, 'x-appwrite-mode' => 'admin', ], $this->getHeaders()), [ - 'minLength' => 8, + 'min' => 8, 'uppercase' => false, 'lowercase' => false, 'number' => false, @@ -3070,7 +3070,7 @@ class ProjectsConsoleClientTest extends Scope ]); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertEquals(8, $response['body']['minLength']); + $this->assertEquals(8, $response['body']['min']); $this->assertEquals(false, $response['body']['uppercase']); $this->assertEquals(false, $response['body']['lowercase']); $this->assertEquals(false, $response['body']['number']); diff --git a/tests/unit/Auth/Validator/PasswordStrengthTest.php b/tests/unit/Auth/Validator/PasswordStrengthTest.php index d8170086bf..af49acb148 100644 --- a/tests/unit/Auth/Validator/PasswordStrengthTest.php +++ b/tests/unit/Auth/Validator/PasswordStrengthTest.php @@ -18,7 +18,7 @@ class PasswordStrengthTest extends TestCase public function testConfiguredPolicy(): void { $validator = new PasswordStrength([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true, @@ -34,10 +34,10 @@ class PasswordStrengthTest extends TestCase $this->assertTrue($validator->isValid('Password123€')); } - public function testMinLengthCanBeEight(): void + public function testMinimumCanBeEight(): void { $validator = new PasswordStrength([ - 'minLength' => 8, + 'min' => 8, ]); $this->assertFalse($validator->isValid('1234567')); @@ -47,7 +47,7 @@ class PasswordStrengthTest extends TestCase public function testAllowEmpty(): void { $validator = new PasswordStrength([ - 'minLength' => 12, + 'min' => 12, 'uppercase' => true, 'lowercase' => true, 'number' => true,