diff options
Diffstat (limited to 'controller/password.php')
| -rw-r--r-- | controller/password.php | 49 |
1 files changed, 39 insertions, 10 deletions
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() | |||
| 28 | 28 | ||
| 29 | function createCaptcha(): array | 29 | function createCaptcha(): array |
| 30 | { | 30 | { |
| 31 | $a = rand(2, 10); | 31 | $a = rand(2, 9); |
| 32 | $b = rand(2, 10); | 32 | $b = rand(2, 9); |
| 33 | return array(toLettersFrench($a), toLettersFrench($b), $a * $b); | 33 | return array(toLettersFrench($a), toLettersFrench($b), $a * $b); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| @@ -61,16 +61,30 @@ function toLettersFrench(int $number): string | |||
| 61 | case 9: | 61 | case 9: |
| 62 | return 'neuf'; | 62 | return 'neuf'; |
| 63 | break; | 63 | break; |
| 64 | case 10: | 64 | default: |
| 65 | return 'dix'; | 65 | return ''; // erreur |
| 66 | break; | ||
| 67 | }; | 66 | }; |
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | // vérifier qu'on a que des chiffres | 69 | // on veut des chiffres |
| 71 | function controlCaptchaInput() | 70 | function controlCaptchaInput(): int |
| 72 | { | 71 | { |
| 73 | //$_POST['captcha'] | 72 | if(is_numeric($_POST['captcha'])) // '2.3' est acceptés |
| 73 | { | ||
| 74 | // (int) supprime les décimales | ||
| 75 | if($_POST['captcha'] == (int) $_POST['captcha']) | ||
| 76 | { | ||
| 77 | return (int) $_POST['captcha']; | ||
| 78 | } | ||
| 79 | else | ||
| 80 | { | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | else | ||
| 85 | { | ||
| 86 | return 0; | ||
| 87 | } | ||
| 74 | } | 88 | } |
| 75 | 89 | ||
| 76 | 90 | ||
| @@ -90,7 +104,7 @@ function createPassword() | |||
| 90 | $subHeading = 'Veuillez choisir le mot de passe que vous utiliserez pour gérer le site.'; | 104 | $subHeading = 'Veuillez choisir le mot de passe que vous utiliserez pour gérer le site.'; |
| 91 | require('view/password.php'); | 105 | require('view/password.php'); |
| 92 | 106 | ||
| 93 | // au rechargement après saisi | 107 | // contrôle de la saisie |
| 94 | if(isset($_POST['motdepasse']) && !empty($_POST['motdepasse']) && isset($_POST['captcha']) && (int) $_POST['captcha'] == $_SESSION['captcha']) | 108 | if(isset($_POST['motdepasse']) && !empty($_POST['motdepasse']) && isset($_POST['captcha']) && (int) $_POST['captcha'] == $_SESSION['captcha']) |
| 95 | { | 109 | { |
| 96 | // caractères non désirés supprimés | 110 | // caractères non désirés supprimés |
| @@ -116,6 +130,15 @@ function createPassword() | |||
| 116 | echo($errorBadCharacters); | 130 | echo($errorBadCharacters); |
| 117 | } | 131 | } |
| 118 | } | 132 | } |
| 133 | // saisie non valide | ||
| 134 | elseif(isset($_POST['captcha']) && controlCaptchaInput() == 0) | ||
| 135 | { | ||
| 136 | sleep(1); | ||
| 137 | echo($header); | ||
| 138 | echo($errorNonValidCaptcha); | ||
| 139 | echo($formulaireNouveauMDP); | ||
| 140 | echo($errorBadCharacters); | ||
| 141 | } | ||
| 119 | // mauvais captcha | 142 | // mauvais captcha |
| 120 | elseif(isset($_POST['captcha']) && (int) $_POST['captcha'] != $_SESSION['captcha']) | 143 | elseif(isset($_POST['captcha']) && (int) $_POST['captcha'] != $_SESSION['captcha']) |
| 121 | { | 144 | { |
| @@ -169,7 +192,13 @@ function connect() | |||
| 169 | header('Location: index.php?page=' . $_GET['from']); | 192 | header('Location: index.php?page=' . $_GET['from']); |
| 170 | exit(); | 193 | exit(); |
| 171 | } | 194 | } |
| 172 | 195 | // saisie non valide | |
| 196 | elseif(isset($_POST['captcha']) && controlCaptchaInput() == 0) | ||
| 197 | { | ||
| 198 | echo($errorNonValidCaptcha); | ||
| 199 | sleep(1); | ||
| 200 | echo($formulaireConnexion); | ||
| 201 | } | ||
| 173 | // mauvais captcha | 202 | // mauvais captcha |
| 174 | elseif(isset($_POST['captcha']) && (int) $_POST['captcha'] != $_SESSION['captcha']) | 203 | elseif(isset($_POST['captcha']) && (int) $_POST['captcha'] != $_SESSION['captcha']) |
| 175 | { | 204 | { |
