mirror of
https://github.com/elyby/accounts.git
synced 2026-04-26 09:12:58 +05:30
Reduce username limit to 16 characters
This commit is contained in:
@@ -37,7 +37,7 @@ class UsernameValidatorTest extends TestCase {
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.username_too_short'], $model->getErrors('field'));
|
||||
|
||||
$model = $this->createModel('erickskrauch_erickskrauch');
|
||||
$model = $this->createModel('mcmodder_mcmodder');
|
||||
$this->validator->validateAttribute($model, 'field');
|
||||
$this->assertSame(['error.username_too_long'], $model->getErrors('field'));
|
||||
|
||||
@@ -50,8 +50,8 @@ class UsernameValidatorTest extends TestCase {
|
||||
// TODO: rewrite this test with @provider usage
|
||||
public function testValidateAttributePattern(): void {
|
||||
$shouldBeValid = [
|
||||
'русский_ник', 'русский_ник_на_грани!', 'numbers1132', '*__*-Stars-*__*', '1-_.!$%^&*()[]',
|
||||
'[ESP]Эрик', 'Свят_помидор;', 'зроблена_ў_беларусі:)',
|
||||
'русский_ник', 'by_ник_на_грани!', 'numbers1132', '*__*-Stars-*__*', '1-_.!$%^&*()[]',
|
||||
'[ESP]Эрик', 'Свят_помидор;',
|
||||
];
|
||||
foreach ($shouldBeValid as $nickname) {
|
||||
$model = $this->createModel($nickname);
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\validators;
|
||||
|
||||
use Closure;
|
||||
@@ -26,9 +28,11 @@ class UsernameValidator extends Validator {
|
||||
$required = new validators\RequiredValidator();
|
||||
$required->message = E::USERNAME_REQUIRED;
|
||||
|
||||
// Using username longer than 16 characters causes the "Failed to encode client:hello" error
|
||||
// during server authentication on Minecraft 1.20 and above
|
||||
$length = new validators\StringValidator();
|
||||
$length->min = 3;
|
||||
$length->max = 21;
|
||||
$length->max = 16;
|
||||
$length->tooShort = E::USERNAME_TOO_SHORT;
|
||||
$length->tooLong = E::USERNAME_TOO_LONG;
|
||||
|
||||
@@ -54,7 +58,7 @@ class UsernameValidator extends Validator {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function executeValidation(Validator $validator, Model $model, string $attribute) {
|
||||
protected function executeValidation(Validator $validator, Model $model, string $attribute): bool {
|
||||
$validator->validateAttribute($model, $attribute);
|
||||
|
||||
return !$model->hasErrors($attribute);
|
||||
|
||||
Reference in New Issue
Block a user