From e4a74650a36bbb72285d38d96ee2a0689031521e Mon Sep 17 00:00:00 2001 From: polo Date: Wed, 3 Aug 2022 02:15:04 +0200 Subject: =?UTF-8?q?captcha=20+=20am=C3=A9liorations=20regex=20+=20erreur?= =?UTF-8?q?=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/password.php | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'controller/password.php') diff --git a/controller/password.php b/controller/password.php index a163619..9d9b45b 100644 --- a/controller/password.php +++ b/controller/password.php @@ -28,8 +28,8 @@ function existPassword() function createCaptcha(): array { - $a = rand(2, 10); - $b = rand(2, 10); + $a = rand(2, 9); + $b = rand(2, 9); return array(toLettersFrench($a), toLettersFrench($b), $a * $b); } @@ -61,16 +61,30 @@ function toLettersFrench(int $number): string case 9: return 'neuf'; break; - case 10: - return 'dix'; - break; + default: + return ''; // erreur }; } -// vérifier qu'on a que des chiffres -function controlCaptchaInput() +// on veut des chiffres +function controlCaptchaInput(): int { - //$_POST['captcha'] + if(is_numeric($_POST['captcha'])) // '2.3' est acceptés + { + // (int) supprime les décimales + if($_POST['captcha'] == (int) $_POST['captcha']) + { + return (int) $_POST['captcha']; + } + else + { + return 0; + } + } + else + { + return 0; + } } @@ -90,7 +104,7 @@ function createPassword() $subHeading = 'Veuillez choisir le mot de passe que vous utiliserez pour gérer le site.'; require('view/password.php'); - // au rechargement après saisi + // contrôle de la saisie if(isset($_POST['motdepasse']) && !empty($_POST['motdepasse']) && isset($_POST['captcha']) && (int) $_POST['captcha'] == $_SESSION['captcha']) { // caractères non désirés supprimés @@ -116,6 +130,15 @@ function createPassword() echo($errorBadCharacters); } } + // saisie non valide + elseif(isset($_POST['captcha']) && controlCaptchaInput() == 0) + { + sleep(1); + echo($header); + echo($errorNonValidCaptcha); + echo($formulaireNouveauMDP); + echo($errorBadCharacters); + } // mauvais captcha elseif(isset($_POST['captcha']) && (int) $_POST['captcha'] != $_SESSION['captcha']) { @@ -169,7 +192,13 @@ function connect() header('Location: index.php?page=' . $_GET['from']); exit(); } - + // saisie non valide + elseif(isset($_POST['captcha']) && controlCaptchaInput() == 0) + { + echo($errorNonValidCaptcha); + sleep(1); + echo($formulaireConnexion); + } // mauvais captcha elseif(isset($_POST['captcha']) && (int) $_POST['captcha'] != $_SESSION['captcha']) { -- cgit v1.2.3