diff --git a/captcha.php b/captcha.php index 0e48396..eb1db33 100644 --- a/captcha.php +++ b/captcha.php @@ -1,17 +1,21 @@ $subject) { $normalPool[] = [ @@ -236,16 +242,13 @@ function buildInboxRound( ]; } - // Mélanger les tableaux shuffle($normalPool); shuffle($spamPool); - // Sélectionner 9 emails normaux et 1 spam $selected = array_slice($normalPool, 0, 9); $selected[] = $spamPool[0]; shuffle($selected); - // Retourner le round return [ 'token' => bin2hex(random_bytes(16)), 'correct_id' => $spamPool[0]['id'], @@ -266,47 +269,51 @@ if (!isset($_SESSION['captcha_round']) || !is_array($_SESSION['captcha_round'])) ); } -// Récupérer le round actuel $round = $_SESSION['captcha_round']; $error = ''; $success = false; $locked = false; +if (!isset($round['emails']) || !is_array($round['emails'])) { + $_SESSION['captcha_round'] = buildInboxRound( + $normalSubjects, + $normalSenders, + $normalPreviews, + $spamSubjects, + $spamSenders, + $spamPreviews, + $maxAttempts + ); + $round = $_SESSION['captcha_round']; +} -// Si formulaire soumis via POST if ($_SERVER['REQUEST_METHOD'] === 'POST') { $postedToken = $_POST['captcha_token'] ?? ''; $selectedMail = $_POST['selected_mail'] ?? ''; - // Si token invalide + if (!hash_equals($round['token'], $postedToken)) { $error = 'Session invalide, recharge la page.'; - // Si plus d'essais } elseif (($round['attempts_left'] ?? 0) <= 0) { $locked = true; $error = 'Tu n’as plus d’essais. Recharge une nouvelle série.'; - // Si mail incorrect } elseif ($selectedMail !== $round['correct_id']) { $_SESSION['captcha_round']['attempts_left']--; $round = $_SESSION['captcha_round']; - // Si plus d'essais après décrémentation + if (($round['attempts_left'] ?? 0) <= 0) { $locked = true; $error = 'Perdu. Tu n’as plus d’essais. Recharge une nouvelle série.'; - // Sinon, message d'erreur } else { $error = 'Ce n’est pas le bon mail. Regarde mieux le message le plus agressif ou trop urgent.'; } - // Si mail correct } else { $_SESSION['captcha_valid'] = true; unset($_SESSION['captcha_round']); $success = true; } } -// Récupérer le nombre d'essais restants -$attemptsLeft = $round['attempts_left'] ?? 0; -// Afficher le captcha +$attemptsLeft = $round['attempts_left'] ?? 0; ?> @@ -388,7 +395,7 @@ $attemptsLeft = $round['attempts_left'] ?? 0; > - + @@ -437,5 +444,3 @@ $attemptsLeft = $round['attempts_left'] ?? 0; - -