diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php index a945f917ec1..c83aa248c6b 100644 --- a/htdocs/admin/security.php +++ b/htdocs/admin/security.php @@ -174,15 +174,15 @@ if ($action == 'maj_pattern') $explodePattern = explode(';', $pattern); $patternInError = false; - if($explodePattern[0] < 1 || $explodePattern[4] < 0){ + if ($explodePattern[0] < 1 || $explodePattern[4] < 0) { $patternInError = true; } - if($explodePattern[0] < $explodePattern[1] + $explodePattern[2] + $explodePattern[3]){ + if ($explodePattern[0] < $explodePattern[1] + $explodePattern[2] + $explodePattern[3]) { $patternInError = true; } - if(!$patternInError){ + if (!$patternInError) { dolibarr_set_const($db, "USER_PASSWORD_PATTERN", $pattern, 'chaine', 0, '', $conf->entity); header("Location: security.php"); exit; diff --git a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php index 3229aa1a616..741c9e314b4 100644 --- a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php +++ b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php @@ -187,31 +187,31 @@ class modGeneratePassPerso extends ModeleGenPassword $spe = str_split($this->Spe); if (count(array_intersect($password_a, $maj)) < $this->NbMaj) { - return 0; + return false; } if (count(array_intersect($password_a, $num)) < $this->NbNum) { - return 0; + return false; } if (count(array_intersect($password_a, $spe)) < $this->NbSpe) { - return 0; + return false; } if (!$this->consecutiveInterationSameCharacter($password)) { - return 0; + return false; } - return 1; + return true; } /** - * Consecutive iterations of the same character + * Check the consecutive iterations of the same character. Return false if the number doesn't match the maximum consecutive value allowed. * * @param string $password Password to check - * @return int 0 if KO, >0 if OK + * @return bool */ - public function consecutiveInterationSameCharacter($password) + private function consecutiveInterationSameCharacter($password) { $last = ""; @@ -224,14 +224,16 @@ class modGeneratePassPerso extends ModeleGenPassword if($c != $last) { $last = $c; $count = 0; - } else { - $count++; + + continue; } - if ($count >= $this->NbRepeat) { - return 0; + $count++; + if ($count > $this->NbRepeat) { + return false; } } - return 1; + + return true; } }