new: [users] username validation added

- >5 && <50 in length required
- trim username to test to avoid whitespace names

- as reported by SK-CERT
cli-modification-summary
iglocska 2022-09-19 01:22:53 +02:00
parent 9a50a5693e
commit 5e0ab5cc38
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 10 additions and 0 deletions

View File

@ -94,6 +94,16 @@ class UsersTable extends AppTable
'message' => __('Password confirmation missing or not matching the password.')
]
])
->add('username', [
'username_policy' => [
'rule' => function($value, $context) {
if (mb_strlen(trim($value)) < 5 || mb_strlen(trim($value)) > 50) {
return __('Invalid username length. Make sure that you provide a username of at least 5 and up to 50 characters in length.');
}
return true;
}
]
])
->requirePresence(['username'], 'create')
->notEmptyString('username', 'Please fill this field');
return $validator;