L'authentification fonctionne -> Ajout classe UserGateway et méthodes de connection dans le controleur et le modele

master
Mehdi 5 years ago
parent b86579f9ce
commit 5b115a949f

@ -0,0 +1,19 @@
<?php
class UserGateway {
private $db;
public function __construct(SqliteDb $sd) {
$this->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'];
}
}

@ -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);

@ -16,6 +16,9 @@ class Controleur {
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();
}
}

@ -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;
}
}

@ -3,8 +3,12 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/xampp/htdocs/BddCorrect/controleur/Controleur.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/DAL/UserGateway.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/SqliteDb.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/modeles/Modele.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/vues/vueLogin.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/Correcteur.php</file>
</group>
</open-files>

Binary file not shown.

@ -1,9 +1,5 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">

@ -72,11 +72,11 @@
<form class = "form-signin" role = "form" method = "post">
<h4 class = "form-signin-heading"></h4>
<input type = "text" class = "form-control"
name = "username" placeholder = "test"
name = "identifiant" placeholder = "test"
required autofocus></br>
<input type = "password" class = "form-control"
name = "password" placeholder = "mdptest" required>
<input type="submit" name="action" value="Se connecter"/>
name = "motdepasse" placeholder = "mdptest" required>
<input type="submit" name="action" value="login"/>
</form>

Loading…
Cancel
Save