From 397fbe8c26f4994ed7f05e72166d7554e5ae4866 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Thu, 28 May 2020 15:19:32 +0200 Subject: [PATCH] =?UTF-8?q?10.2.dev11=20bloquer=20l'acc=C3=A8s=20au=20comp?= =?UTF-8?q?te=20trop=20de=20mauvaises=20=20connexions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/core.php | 8 ++++++-- core/module/user/user.php | 41 ++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/core/core.php b/core/core.php index 1192dd54..1f1b8019 100755 --- a/core/core.php +++ b/core/core.php @@ -36,10 +36,14 @@ class common { const THUMBS_WIDTH = 640; // Contrôle d'édition temps max en secondes. - const ACCESS_TIMER = 360; + const ACCESS_TIMER = 1800; + // Nombre d'essais + const CONNECT_ATTEMPT = 3; + // Temps mort + const CONNECT_TIMEOUT = 1800; // Numéro de version - const ZWII_VERSION = '10.2.00.dev10'; + const ZWII_VERSION = '10.2.00.dev11'; const ZWII_UPDATE_CHANNEL = "v10"; public static $actions = []; diff --git a/core/module/user/user.php b/core/module/user/user.php index 043a381d..10714bf0 100755 --- a/core/module/user/user.php +++ b/core/module/user/user.php @@ -43,14 +43,14 @@ class user extends common { if($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true) !== $this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true)) { self::$inputNotices['userAddConfirmPassword'] = 'Incorrect'; $check = false; - } + } // Crée l'utilisateur $userFirstname = $this->getInput('userAddFirstname', helper::FILTER_STRING_SHORT, true); $userLastname = $this->getInput('userAddLastname', helper::FILTER_STRING_SHORT, true); $userMail = $this->getInput('userAddMail', helper::FILTER_MAIL, true); // Pas de nom saisi - if (empty($userFirstname) || - empty($userLastname) || + if (empty($userFirstname) || + empty($userLastname) || empty($this->getInput('userAddPassword', helper::FILTER_STRING_SHORT, true)) || empty($this->getInput('userAddConfirmPassword', helper::FILTER_STRING_SHORT, true))) { $check=false; @@ -121,7 +121,7 @@ class user extends common { 'redirect' => helper::baseUrl() . 'user', 'notification' => 'Action non autorisée' ]); - } + } // Bloque la suppression de son propre compte elseif($this->getUser('id') === $this->getUrl(2)) { // Valeurs en sortie @@ -147,13 +147,13 @@ class user extends common { */ public function edit() { if ($this->getUrl(3) !== $_SESSION['csrf'] && - $this->getUrl(4) !== $_SESSION['csrf']) { + $this->getUrl(4) !== $_SESSION['csrf']) { // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . 'user', 'notification' => 'Action non autorisée' ]); - } + } // Accès refusé if( // L'utilisateur n'existe pas @@ -332,6 +332,13 @@ class user extends common { // Soumission du formulaire if($this->isPost()) { $userId = $this->getInput('userLoginId', helper::FILTER_ID, true); + // Contrôle du time out + if ( $this->getData(['user',$userId,'connectTimeout']) + self::CONNECT_TIMEOUT > time() && + $this->getData(['user',$userId,'connectFail']) > self::CONNECT_ATTEMPT ) { + $this->addOutput([ + 'notification' => 'Accès bloqué pour ' . self::CONNECT_TIMEOUT . ' minutes' + ]); + } // Connexion si les informations sont correctes if( password_verify($this->getInput('userLoginPassword', helper::FILTER_STRING_SHORT, true), $this->getData(['user', $userId, 'password'])) @@ -348,13 +355,15 @@ class user extends common { AND $this->getData(['user', $userId, 'group']) < self::GROUP_ADMIN ) { $this->addOutput([ - 'notification' => 'Seul un administrateur peur se connecter lors d\'une maintenance', + 'notification' => 'Seul un administrateur peut se connecter lors d\'une maintenance', 'redirect' => helper::baseUrl(), 'state' => false ]); } - // Valeurs en sortie en cas de réussite else { + // RAZ compteur échec connexion + $this->setData(['user',$userId,'connectFail',0 ]); + // Valeurs en sortie en cas de réussite $this->addOutput([ 'notification' => 'Connexion réussie', 'redirect' => helper::baseUrl() . str_replace('_', '/', str_replace('__', '#', $this->getUrl(2))), @@ -364,9 +373,23 @@ class user extends common { } // Sinon notification d'échec else { + // Incrémenter le compteur d'échec de connexion si l'utilisateur existe + if ( is_array($this->getdata(['user',$userId])) ) { + $this->setData(['user',$userId,'connectFail',$this->getdata(['user',$userId,'connectFail']) + 1 ]); + } + // Mettre à jour le timer + if ( $this->getdata(['user',$userId,'connectFail']) > self::CONNECT_ATTEMPT) { + $notification = 'Trop de tentatives, accès bloqué durant ' . self::CONNECT_TIMEOUT / 360 . ' minutes après chaque tentative infructueuse'; + // Ne pas incrémenter le timer si actif + if ($this->getData(['user',$userId,'connectTimeout']) + self::CONNECT_TIMEOUT < time() ) { + $this->setData(['user',$userId,'connectTimeout', time()]); + } + } else { + $notification = 'Identifiant ou mot de passe incorrect'; + } // Valeurs en sortie $this->addOutput([ - 'notification' => 'Identifiant ou mot de passe incorrect' + 'notification' => $notification ]); } }