From 90673ef19133e037cf401773f4262ba3d7d050bf Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 3 Aug 2025 04:06:53 +0200 Subject: =?UTF-8?q?r=C3=A9organisation=204:=20d=C3=A9placement=20de=20fich?= =?UTF-8?q?iers,=20plus=20que=20des=20contr=C3=B4leurs=20dans=20/src/contr?= =?UTF-8?q?oller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Captcha.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/Captcha.php (limited to 'src/Captcha.php') diff --git a/src/Captcha.php b/src/Captcha.php new file mode 100644 index 0000000..c60a186 --- /dev/null +++ b/src/Captcha.php @@ -0,0 +1,52 @@ +a = rand(2, 9); + $this->b = rand(2, 9); + $this->solution = $this->a * $this->b; + } + + public function getA(): string + { + return $this->toLettersFrench($this->a); + } + public function getB(): string + { + return $this->toLettersFrench($this->b); + } + public function getSolution(): int + { + return $this->solution; + } + + private function toLettersFrench(int $number): string + { + return match($number){ + 2 => 'deux', + 3 => 'trois', + 4 => 'quatre', + 5 => 'cinq', + 6 => 'six', + 7 => 'sept', + 8 => 'huit', + 9 => 'neuf', + default => '', // erreur + }; + } + static public function controlInput(string $input = '0'): int + { + // un POST est une chaîne qu'on doit convertir en nombre dans deux conditions: + // test de format: $input est un nombre + // test d'intégrité: supprimer les décimales avec (int) ne change pas la valeur du nombre + return is_numeric($input) && $input == (int)$input ? (int)$input : 0; + } +} \ No newline at end of file -- cgit v1.2.3