From a3ccbd8bf094668b007f3de8f4cf38f3f9e13143 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 10 Mar 2018 17:07:14 +0100 Subject: [PATCH] Username requirement adjustments. --- src/Controllers/AuthController.php | 1 + src/Users/User.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index eb949e06..befda5d8 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -15,6 +15,7 @@ class AuthController extends Controller 'trim' => 'Your username may not start or end with spaces!', 'short' => "Your username is too short, it has to be at least " . User::USERNAME_MIN_LENGTH . " characters!", 'long' => "Your username is too long, it can't be longer than " . User::USERNAME_MAX_LENGTH . " characters!", + 'double-spaces' => "Your username can't contain double spaces.", 'invalid' => 'Your username contains invalid characters.', 'spacing' => 'Please use either underscores or spaces, not both!', ]; diff --git a/src/Users/User.php b/src/Users/User.php index 201ccf8a..bc6b9af1 100644 --- a/src/Users/User.php +++ b/src/Users/User.php @@ -14,6 +14,7 @@ class User extends Model public const USERNAME_MIN_LENGTH = 3; public const USERNAME_MAX_LENGTH = 16; + public const USERNAME_REGEX = '#^[A-Za-z0-9-_ ]+$#u'; protected $primaryKey = 'user_id'; @@ -55,7 +56,11 @@ class User extends Model return 'long'; } - if (strpos($username, ' ') !== false || !preg_match('#^[A-Za-z0-9-\[\]_ ]+$#u', $username)) { + if (strpos($username, ' ') !== false) { + return 'double-spaces'; + } + + if (!preg_match(self::USERNAME_REGEX, $username)) { return 'invalid'; }