]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #5978 from MrPetovan/task/make-username-length-configurable
authorMichael Vogel <icarus@dabo.de>
Sun, 21 Oct 2018 21:42:44 +0000 (23:42 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Oct 2018 21:42:44 +0000 (23:42 +0200)
Make username length configurable

config/config.ini.php
src/Model/User.php

index a324e709ec93c8016b7fbedf97a95eec0b69073c..3031d7d5047acd600318f07ecf2b48532c8e8279 100644 (file)
@@ -369,6 +369,18 @@ throttle_limit_month = 0
 ; For instance if your URL is 'http://example.com/directory/subdirectory', set urlpath to 'directory/subdirectory'.
 urlpath =
 
+; username_min_length (Integer)
+; The minimum character length a username can be.
+; This length is check once the username has been trimmed and multiple spaces have been collapsed into one.
+; Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars.
+username_min_length = 3
+
+; username_max_length (Integer)
+; The maximum character length a username can be.
+; This length is check once the username has been trimmed and multiple spaces have been collapsed into one.
+; Minimum for this config value is 1. Maximum is 64 as the resulting profile URL mustn't be longer than 255 chars.
+username_max_length = 48
+
 ; worker_cooldown (Integer)
 ; Cooldown period in seconds after each worker function call.
 worker_cooldown = 0
index 63aaa1e3de2c59312e1033bbd2ad6d5807e44210..bca3e73f5dd6d898588f48dde020c6dd1d49f4ea 100644 (file)
@@ -466,19 +466,30 @@ 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(64, intval(Config::get('system', 'username_min_length', 3))));
+               $username_max_length = max(1, min(64, intval(Config::get('system', 'username_max_length', 48))));
+
+               if ($username_min_length > $username_max_length) {
+                       logger(L10n::t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length), LOGGER_WARNING);
+                       $tmp = $username_min_length;
+                       $username_min_length = $username_max_length;
+                       $username_max_length = $tmp;
+               }
+
+               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 characters.', $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."));
                        }
                }