From eeeb5c3db8d991d940059de99c9fedbcc1cd79bc Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 26 Jun 2020 10:01:14 +0200 Subject: [PATCH] =?UTF-8?q?10.2.01=20gestion=20des=20=C3=A9checs=20de=20co?= =?UTF-8?q?nnexion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 4 +++ core/core.php | 12 +++++-- core/module/user/user.php | 68 +++++++++++++++++++++------------------ 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 92b8ac2d..fdbaaabd 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changelog +## version 10.2.01 +- Correction : + - Optimisation et correction de l'algorithme de contrôle d'accès. + ## version 10.2.00 - Mise à jour : - jQuery v3.5.1 diff --git a/core/core.php b/core/core.php index 905d16d3..c5a6ae9f 100755 --- a/core/core.php +++ b/core/core.php @@ -39,7 +39,7 @@ class common { const ACCESS_TIMER = 1800; // Numéro de version - const ZWII_VERSION = '10.2.00'; + const ZWII_VERSION = '10.2.01'; const ZWII_UPDATE_CHANNEL = "v10"; public static $actions = []; @@ -1314,10 +1314,18 @@ class common { } // Version 10.2.00 if ($this->getData(['core', 'dataVersion']) < 10200) { - $this->deleteData(['admin','colorButtonText']); + // Paramètres du compte connecté + $this->setData(['user', $this->getUser('id'), 'connectFail',0]); + $this->setData(['user', $this->getUser('id'), 'connectTimeout',0]); + $this->setData(['user', $this->getUser('id'), 'accessTimer',0]); + $this->setData(['user', $this->getUser('id'), 'accessUrl','']); + $this->setData(['user', $this->getUser('id'), 'accessCsrf',$_SESSION['csrf']]); + // Paramètres de sécurité $this->setData(['config', 'connect', 'attempt',999]); $this->setData(['config', 'connect', 'timeout',0]); $this->setData(['config', 'connect', 'log',false]); + // Thème + $this->deleteData(['admin','colorButtonText']); // Remettre à zéro le thème pour la génération du CSS du blog if (file_exists(self::DATA_DIR . 'theme.css')) { unlink(self::DATA_DIR . 'theme.css'); diff --git a/core/module/user/user.php b/core/module/user/user.php index cc130657..afaab5d0 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -338,27 +338,45 @@ class user extends common { if($this->isPost()) { $userId = $this->getInput('userLoginId', helper::FILTER_ID, true); - // le userId n'existe pas, créer ou mettre à jour une entrée dans la liste noire + /** + * Aucun compte existant + */ if( !$this->getData(['user', $userId])) { //Stockage de l'IP $this->setData([ 'blacklist', $userId, [ - 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) ? $this->getData(['blacklist',$userId,'connectFail']) + 1 : 1, + 'connectFail' => $this->getData(['blacklist',$userId,'connectFail']) + 1, 'lastFail' => time(), 'ip' => $_SERVER['REMOTE_ADDR'] ] ]); - $notification = 'Identifiant ou mot de passe incorrect'; + if ( $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) ) { + $notification = 'Trop de tentatives, compte verrouillé'; + } else { + $notification = 'Identifiant ou mot de passe incorrect'; + } + // Valeurs en sortie + $this->addOutput([ + 'notification' => $notification + ]); } /** - * Compte valide : - * Mot de passe - * Groupe - */ - if( $this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() + * Le compte existe + */ + + // Cas 4 : le délai de blocage est dépassé et le compte est au max - Réinitialiser + if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() + AND $this->getData(['user',$userId,'connectFail']) === $this->getData(['config', 'connect', 'attempt']) ) { + $this->setData(['user',$userId,'connectFail',0 ]); + $this->setData(['user',$userId,'connectTimeout',0 ]); + } + // Check la présence des variables et contrôle du blocage du compte si valeurs dépassées + // Vérification du mot de passe et du groupe + if ( + ( $this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) ) < time() AND $this->getData(['user',$userId,'connectFail']) < $this->getData(['config', 'connect', 'attempt']) AND password_verify($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true), $this->getData(['user', $userId, 'password'])) AND $this->getData(['user', $userId, 'group']) >= self::GROUP_MEMBER @@ -380,9 +398,6 @@ class user extends common { ]); } else { - // RAZ compteur échec connexion - $this->setData(['user',$userId,'connectFail',0 ]); - $this->setData(['user',$userId,'connectTimeout',0 ]); // Valeurs en sortie $this->addOutput([ 'notification' => 'Connexion réussie', @@ -393,27 +408,18 @@ class user extends common { } // Sinon notification d'échec else { - // L'utilisateur existe : incrémenter le compteur d'échec de connexion - if ( is_array($this->getdata(['user',$userId])) - ) { + $notification = 'Identifiant ou mot de passe incorrect'; + // Cas 1 le nombre de connexions est inférieur aux tentatives autorisées : incrément compteur d'échec + if ($this->getData(['user',$userId,'connectFail']) < $this->getData(['config', 'connect', 'attempt'])) { $this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]); - // Mettre à jour le timer et notifier - if ( $this->getdata(['user',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) - ) { - $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; - // Incrémenter le timer - if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) < time() ) { - $this->setData(['user',$userId,'connectTimeout', time()]); - } - } else { - $notification = 'Identifiant ou mot de passe incorrect'; - } - // L'utilisateur n'existe pas - // Bloquer l'IP après les tentatives autorisées avec ce compte, - } elseif ( - $this->getData(['blacklist',$userId,'connectFail']) >= $this->getData(['config', 'connect', 'attempt']) - ) { - $notification = 'Trop de tentatives, compte verrouillé'; + } + // Cas 2 la limite du nombre de connexion est atteinte : placer le timer + if ( $this->getdata(['user',$userId,'connectFail']) == $this->getData(['config', 'connect', 'attempt']) ) { + $this->setData(['user',$userId,'connectTimeout', time()]); + } + // Cas 3 le délai de bloquage court + if ($this->getData(['user',$userId,'connectTimeout']) + $this->getData(['config', 'connect', 'timeout']) > time() ) { + $notification = 'Trop de tentatives, accès bloqué durant ' . ($this->getData(['config', 'connect', 'timeout']) / 60) . ' minutes.'; } // Journalisation $dataLog = strftime('%d/%m/%y',time()) . ';' . strftime('%R',time()) . ';' ;