diff --git a/BddCorrect/DAL/UserGateway.php b/BddCorrect/DAL/UserGateway.php new file mode 100644 index 0000000..6a1a58c --- /dev/null +++ b/BddCorrect/DAL/UserGateway.php @@ -0,0 +1,19 @@ +db = $sd; + } + + public function getPassword($identifiant){ + $q = "SELECT password FROM login WHERE username= "; + $stmt = $this->db->prepare("SELECT * FROM login WHERE username= ?"); + $stmt->bindParam(1, $identifiant); + $result = $stmt->execute(); + $passArray = $result->fetcharray(); + return $passArray['password']; + } + } + diff --git a/BddCorrect/SqliteDb.php b/BddCorrect/SqliteDb.php index 3d78d87..34aefae 100644 --- a/BddCorrect/SqliteDb.php +++ b/BddCorrect/SqliteDb.php @@ -6,6 +6,7 @@ class SqliteDb extends SQLite3 function __construct() { $this->open('test.db'); + $this->createLogin(); //$this->createTable(); } @@ -100,7 +101,7 @@ class SqliteDb extends SQLite3 $mdp = password_hash('mdptest', PASSWORD_DEFAULT); $username = 'test'; $this->exec('DROP TABLE login'); - $this->exec('CREATE TABLE login ( username STRING, password STRING'); + $this->exec('CREATE TABLE login ( username STRING, password STRING)'); $stmt = $this->prepare("INSERT INTO login VALUES(? , ?)"); $stmt->bindParam(1, $username); diff --git a/BddCorrect/controleur/Controleur.php b/BddCorrect/controleur/Controleur.php index f5536dc..e72db61 100644 --- a/BddCorrect/controleur/Controleur.php +++ b/BddCorrect/controleur/Controleur.php @@ -15,7 +15,10 @@ class Controleur { case NULL: require ($rep.$vues['vueLogin']); break; - + + case 'login' : + $this->verificationConnexion(); + break; default: $dVueEreur[] ="Erreur d'appel php"; @@ -42,5 +45,19 @@ class Controleur { $dVueQuestions = $model->afficherQuestions(); require ($rep.$vues['vuePrincipale']); } + + function verificationConnexion(){ + global $rep,$vues; + + $id = $_POST['identifiant']; + $mdp = $_POST['motdepasse']; + + $modele = new Modele(); + if($modele->connection($id,$mdp)==null){ + echo 'AAAAAAAAAA'; + require($rep.$vues['vueLogin']); + } + else $this->afficherQuestions(); + } } diff --git a/BddCorrect/modeles/Modele.php b/BddCorrect/modeles/Modele.php index f91880f..8e222de 100644 --- a/BddCorrect/modeles/Modele.php +++ b/BddCorrect/modeles/Modele.php @@ -12,5 +12,14 @@ class Modele { return $tabQuestions; } + function connection($id, $mdp){ + $ug = new UserGateway(new SqliteDb()); + $vraiMdp = $ug->getPassword($id); + if(!password_verify($mdp, $vraiMdp)){ + return null; + } + return 1; + } + } diff --git a/BddCorrect/nbproject/private/private.xml b/BddCorrect/nbproject/private/private.xml index 74b6be9..331476b 100644 --- a/BddCorrect/nbproject/private/private.xml +++ b/BddCorrect/nbproject/private/private.xml @@ -3,8 +3,12 @@ + file:/C:/xampp/htdocs/BddCorrect/controleur/Controleur.php + file:/C:/xampp/htdocs/BddCorrect/DAL/UserGateway.php file:/C:/xampp/htdocs/BddCorrect/SqliteDb.php file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php + file:/C:/xampp/htdocs/BddCorrect/modeles/Modele.php + file:/C:/xampp/htdocs/BddCorrect/vues/vueLogin.php file:/C:/xampp/htdocs/BddCorrect/Correcteur.php diff --git a/BddCorrect/test.db b/BddCorrect/test.db index 2d2705b..a495206 100644 Binary files a/BddCorrect/test.db and b/BddCorrect/test.db differ diff --git a/BddCorrect/vues/VuePrincipale.php b/BddCorrect/vues/VuePrincipale.php index 1c17c5f..8ec8fc3 100644 --- a/BddCorrect/vues/VuePrincipale.php +++ b/BddCorrect/vues/VuePrincipale.php @@ -1,9 +1,5 @@ - + diff --git a/BddCorrect/vues/vueLogin.php b/BddCorrect/vues/vueLogin.php index 1257d75..1f6b557 100644 --- a/BddCorrect/vues/vueLogin.php +++ b/BddCorrect/vues/vueLogin.php @@ -72,11 +72,11 @@

- + name = "motdepasse" placeholder = "mdptest" required> +