mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Rename password strength minimum field
This commit is contained in:
1 parent
50df089517
commit
06eb6edeab
11 files changed
+44
-44
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ class Get extends Action
|
||||
],
|
||||
'password-strength' => [
|
||||
new Document(\array_merge([
|
||||
'minLength' => 8,
|
||||
'min' => 8,
|
||||
'uppercase' => false,
|
||||
'lowercase' => false,
|
||||
'number' => false,
|
||||
|
||||
+5
-5
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -84,7 +84,7 @@ class Create extends Action
|
||||
'limit' => 0,
|
||||
'maxSessions' => 0,
|
||||
'passwordStrength' => [
|
||||
'minLength' => 8,
|
||||
'min' => 8,
|
||||
'uppercase' => false,
|
||||
'lowercase' => false,
|
||||
'number' => false,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user