From 2ba8506608a61c031a681f1183dc459a06dce994 Mon Sep 17 00:00:00 2001 From: Laurent De Coninck Date: Mon, 7 Oct 2019 17:53:23 +0200 Subject: [PATCH] validate the 0 as min value consecutive; meaning not take that rule into account --- htdocs/admin/security.php | 2 +- .../generate/modGeneratePassPerso.class.php | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/htdocs/admin/security.php b/htdocs/admin/security.php index c4c8026e076..7fa5bb3c28f 100644 --- a/htdocs/admin/security.php +++ b/htdocs/admin/security.php @@ -174,7 +174,7 @@ if ($action == 'maj_pattern') $explodePattern = explode(';', $pattern); $patternInError = false; - if($explodePattern[0] < 1 || $explodePattern[4] < 1){ + if($explodePattern[0] < 1){ $patternInError = true; } diff --git a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php index bccb1353087..f8c02cc95f8 100644 --- a/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php +++ b/htdocs/core/modules/security/generate/modGeneratePassPerso.class.php @@ -187,31 +187,32 @@ 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 = ""; $count = 0; @@ -220,14 +221,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; } }