]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/User.php
Changing default/max values for username_min/max_length
[friendica.git] / src / Model / User.php
index 17c9831ca92530b5d8c9bdd1673094dbf518d6a8..4dcd5070483a351cc7af4e2145206c4ca4a8d0c9 100644 (file)
@@ -5,7 +5,7 @@
  */
 namespace Friendica\Model;
 
-use DivineOmega\PasswordExposed\PasswordStatus;
+use DivineOmega\PasswordExposed;
 use Exception;
 use Friendica\Core\Addon;
 use Friendica\Core\Config;
@@ -20,7 +20,6 @@ use Friendica\Util\Crypto;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use LightOpenID;
-use function password_exposed;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -280,7 +279,14 @@ class User
         */
        public static function isPasswordExposed($password)
        {
-               return password_exposed($password) === PasswordStatus::EXPOSED;
+               $cache = new \DivineOmega\DOFileCachePSR6\CacheItemPool();
+               $cache->changeConfig([
+                       'cacheDirectory' => get_temppath() . '/password-exposed-cache/',
+               ]);
+
+               $PasswordExposedCHecker = new PasswordExposed\PasswordExposedChecker(null, $cache);
+
+               return $PasswordExposedCHecker->passwordExposed($password) === PasswordExposed\PasswordStatus::EXPOSED;
        }
 
        /**
@@ -460,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(150, intval(Config::get('system', 'username_min_length', 3))));
+               $username_max_length = max(1, min(150, 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) < 3) {
-                       throw new Exception(L10n::t('Name too short.'));
+
+               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) > $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."));
                        }
                }