From d360bf926a5aea4461cdf79a0ab115159155138b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 20 Oct 2018 16:33:54 -0400 Subject: [PATCH] Use username_min/max_length config keys in Model\User::create --- src/Model/User.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Model/User.php b/src/Model/User.php index 63aaa1e3de..71c1306b8e 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -466,19 +466,23 @@ class User // collapse multiple spaces in name $username = preg_replace('/ +/', ' ', $username); - if (mb_strlen($username) > 48) { - throw new Exception(L10n::t('Please use a shorter name.')); + $username_min_length = max(1, min(255, intval(Config::get('system', 'username_min_length', 0)))); + $username_max_length = max(1, min(255, intval(Config::get('system', 'username_max_length', 0)))); + + if (mb_strlen($username) < $username_min_length) { + throw new Exception(L10n::tt('Username should be at least %s character.', 'Username should be at least %s character.', $username_min_length)); } - if (mb_strlen($username) < 3) { - throw new Exception(L10n::t('Name too short.')); + + if (mb_strlen($username) > $username_max_length) { + throw new Exception(L10n::tt('Username should be at most %s character.', 'Username should be at most %s characters.', $username_max_length)); } // So now we are just looking for a space in the full name. $loose_reg = Config::get('system', 'no_regfullname'); if (!$loose_reg) { $username = mb_convert_case($username, MB_CASE_TITLE, 'UTF-8'); - if (!strpos($username, ' ')) { - throw new Exception(L10n::t("That doesn't appear to be your full \x28First Last\x29 name.")); + if (strpos($username, ' ') === false) { + throw new Exception(L10n::t("That doesn't appear to be your full (First Last) name.")); } }