From 238a111a6b104f5892e62683d5e4883254079f2b Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Mon, 20 Feb 2023 22:33:21 +0100 Subject: [PATCH 1/2] Ajout de la classe Validate.php --- Source/Config/Validate.php | 60 ++++++++++++++++++++++++++++++++++++++ Source/Config/config.php | 4 +++ 2 files changed, 64 insertions(+) create mode 100644 Source/Config/Validate.php diff --git a/Source/Config/Validate.php b/Source/Config/Validate.php new file mode 100644 index 0000000..0520d83 --- /dev/null +++ b/Source/Config/Validate.php @@ -0,0 +1,60 @@ += 3 && preg_match("#[a-zA-Z0-9]+#", $pseudo) && strlen($pseudo) <= $pseudoMaxLength){ + return true; + } + else return false; + } + + /** + * Valide un mot de passe en vérifiant que la longueur est suffisante, qu'il contient au moins un chiffre et une lettre, + * et qu'il respecte la longueur maximale définie globalement. + * + * @param string $password Le mot de passe à valider. + * @return bool Vrai si le mot de passe est valide, faux sinon. + */ + + static function password($password) : bool + { + global $passwordMaxLength; + if(strlen($password) >= 8 && strlen($password) <=$passwordMaxLength && preg_match("#[0-9]+#", $password) && preg_match("#[a-zA-Z]+#", $password)){ + return true; + } + else return false; + } + + + + +} \ No newline at end of file diff --git a/Source/Config/config.php b/Source/Config/config.php index 161d220..5a0ce6f 100644 --- a/Source/Config/config.php +++ b/Source/Config/config.php @@ -6,3 +6,7 @@ $rep = __DIR__ . '/../'; // Vues $views['form'] = 'Views/HTML/form.php'; $views['admin'] = 'Views/HTML/admin.php'; + +$emailMaxLength=150; +$pseudoMaxLength=50; +$passwordMaxLength=500; \ No newline at end of file From 5755fe44692b4bbba90b3ba9fa6ea49add07e865 Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Mon, 20 Feb 2023 22:54:19 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Ajout=20de=20fonctions=20de=20validation=20?= =?UTF-8?q?pour=20chaque=20attribut=20avec=20un=20nom=20diff=C3=A9rents=20?= =?UTF-8?q?dans=20les=20tables=20de=20la=20base=20de=20donn=C3=A9es,=20aup?= =?UTF-8?q?aravant=20il=20n'y=20avit=20que=20celle=20pour=20la=20connectio?= =?UTF-8?q?n=20de=20l'administrateur=20du=20formulaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Config/Validate.php | 55 ++++++++++++++++++++++++++++++++++++++ Source/Config/config.php | 7 ++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Source/Config/Validate.php b/Source/Config/Validate.php index 0520d83..99c7a54 100644 --- a/Source/Config/Validate.php +++ b/Source/Config/Validate.php @@ -54,7 +54,62 @@ class Validate else return false; } + /** + * Vérifie si le mot-clé est valide. + * + * @param string $keyword Le mot-clé à vérifier. + * @return bool Vrai si le mot-clé est valide, faux sinon. + */ + + static function keyWord($keyword) : bool + { + global $keyWordMaxLength; + if (isset($keyword) && strlen($keyword) <= $keyWordMaxLength && strlen($keyword) >= 3) + return true; + else return false; + } + /** + * Vérifie si le titre est valide. + * + * @param string $title Le titre à vérifier. + * @return bool Vrai si le titre est valide, faux sinon. + */ + static function title($title) : bool + { + global $titleMaxLength; + if (isset($title) && strlen($title) <= $titleMaxLength && strlen($title) >= 3) + return true; + else return false; + } + /** + * Vérifie si le type est valide. + * + * @param string $type Le type à vérifier. + * @return bool Vrai si le type est valide, faux sinon. + */ + + static function type($type) : bool + { + global $typeMaxLength; + if (isset($type) && strlen($type) <= $typeMaxLength && strlen($type) >=3) + return true; + else return false; + } + + /** + * Vérifie si la réponse est valide. + * + * @param string $response La réponse à vérifier. + * @return bool Vrai si la réponse est valide, faux sinon. + */ + + static function response($response) : bool{ + global $responseMaxLength; + if(isset($response) && strlen($response) <= $responseMaxLength) + return true; + else return false; + } } \ No newline at end of file diff --git a/Source/Config/config.php b/Source/Config/config.php index 5a0ce6f..6ac43ef 100644 --- a/Source/Config/config.php +++ b/Source/Config/config.php @@ -9,4 +9,9 @@ $views['admin'] = 'Views/HTML/admin.php'; $emailMaxLength=150; $pseudoMaxLength=50; -$passwordMaxLength=500; \ No newline at end of file +$passwordMaxLength=500; +$keyWordMaxLength=50; +$titleMaxLength=50; +$typeMaxLength=50; +$responseMaxLength=200; +