From 70e733d0b6cee9363f25d18b740d9d51395f9421 Mon Sep 17 00:00:00 2001 From: majean5 Date: Tue, 13 Dec 2022 16:38:37 +0100 Subject: [PATCH] fin validation --- config/Validation.php | 38 ++++++++++++++++++++++++++++++ controleurs/ControleurVisiteur.php | 5 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/config/Validation.php b/config/Validation.php index fb6eaa4..dfad6b4 100644 --- a/config/Validation.php +++ b/config/Validation.php @@ -6,10 +6,20 @@ $dataVueEreur[] ="Nom d'utilisateur manquant"; throw new Exception('pas de username'); } + $username = Validation::clear_string($username); + if($username == false){ + $dataVueEreur[] = "Sanitizing error"; + throw new Exception('sanitizing fail'); + } if (!isset($mdp)||$mdp=="") { $dataVueEreur[] ="Mot de passe manquant"; throw new Exception('pas de password'); } + $mdp = Validation::clear_string($mdp); + if($mdp == false){ + $dataVueEreur[] = "Sanitizing error"; + throw new Exception('sanitizing fail'); + } return $dataVueEreur; } @@ -18,14 +28,29 @@ $dataVueEreur[] ="Nom d'utilisateur manquant"; throw new Exception('pas de username'); } + $username = Validation::clear_string($username); + if($username == false){ + $dataVueEreur[] = "Sanitizing error"; + throw new Exception('sanitizing fail'); + } if (!isset($pwd1)||$pwd1==="") { $dataVueEreur[] ="Mot de passe manquant"; throw new Exception('pas de password'); } + $pwd1 = Validation::clear_string($pwd1); + if($pwd1 == false){ + $dataVueEreur[] = "Sanitizing error"; + throw new Exception('sanitizing fail'); + } if (!isset($pwd2)||$pwd2==="") { $dataVueEreur[] ="Confirmation mot de passe manquant"; throw new Exception('pas de confirmation password'); } + $pwd2 = Validation::clear_string($pwd2); + if($pwd2 == false){ + $dataVueEreur[] = "Sanitizing error"; + throw new Exception('sanitizing fail'); + } if($pwd1 !== $pwd2){ $dataVueEreur[]="Mot de passe et confirmation différents"; throw new Exception("Mot de passe et confirmation différents"); @@ -33,6 +58,19 @@ return $dataVueEreur; } + static function val_intitule($intitule, $dataVueEreur){ + if (!isset($intitule)||$intitule==="") { + $dataVueEreur[] ="Intitulé manquant"; + throw new Exception('pas d\'intitule'); + } + $intitule = Validation::clear_string($intitule); + if($intitule == false){ + $dataVueEreur[] = "Sanitizing error"; + throw new Exception('sanitizing fail'); + } + return $dataVueEreur; + } + static function clear_string($champ){ return filter_var($champ, FILTER_SANITIZE_SPECIAL_VAR); } diff --git a/controleurs/ControleurVisiteur.php b/controleurs/ControleurVisiteur.php index c07f498..dd1f9cc 100644 --- a/controleurs/ControleurVisiteur.php +++ b/controleurs/ControleurVisiteur.php @@ -62,8 +62,7 @@ class ControleurVisiteur { global $rep,$vues,$dataView; $usrname=$_POST['login']; $pwd=$_POST['mdp']; - Validation::clear_string($pwd); - Validation::val_connexion($usrname,$pwd,$vues_erreur); + $vues_erreur=Validation::val_connexion($usrname,$pwd,$vues_erreur); $model= new VisiteurModel(); if($model->existUser($usrname)){ if(password_verify($pwd,$model->getHashedPassword($usrname))){ @@ -100,6 +99,7 @@ class ControleurVisiteur { public function creerListe(array $vues_erreur){ global $rep, $vues; $nom=$_POST['name']; + $vues_erreur=Validation::val_intitule($nom, $vues_erreur); $model = new ListeModel(); if(isset($_SESSION['login'])){ foreach($_POST['private'] as $valeur){ @@ -127,6 +127,7 @@ class ControleurVisiteur { require($rep.$vues['creerTache']); $intitule = $_POST['intitule']; + $vues_erreur=Validation::val_intitule($intitule, $vues_erreur); $model = new ListeModel(); $model->creerTache();