mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-02 14:17:26 +02:00
Explain how to impose restrictions on characters/length for usernames
This commit is contained in:
@@ -160,6 +160,14 @@ The username in the third parameter is optional. You can pass `null` there if yo
|
|||||||
|
|
||||||
If you want to enforce unique usernames, on the other hand, simply call `registerWithUniqueUsername` instead of `register`, and be prepared to catch the `DuplicateUsernameException`.
|
If you want to enforce unique usernames, on the other hand, simply call `registerWithUniqueUsername` instead of `register`, and be prepared to catch the `DuplicateUsernameException`.
|
||||||
|
|
||||||
|
**Note:** When accepting and managing usernames, you may want to exclude non-printing control characters and certain printable special characters, as in the character class `[\x00-\x1f\x7f\/:\\]`. In order to do so, you could wrap the call to `Auth#register` or `Auth#registerWithUniqueUsername` inside a conditional branch, for example by only accepting usernames when the following condition is satisfied:
|
||||||
|
|
||||||
|
```php
|
||||||
|
if (\preg_match('/[\x00-\x1f\x7f\/:\\\\]/', $username) === 0) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
For email verification, you should build an URL with the selector and token and send it to the user, e.g.:
|
For email verification, you should build an URL with the selector and token and send it to the user, e.g.:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
Reference in New Issue
Block a user