-
Notifications
You must be signed in to change notification settings - Fork 0
/
connexion.php
62 lines (59 loc) · 1.64 KB
/
connexion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once 'header.php';
$errors = [];
$username = "";
$email = "";
$mdp = "";
$hash = "";
$password = "";
if (!empty($_POST)) {
$email = $_POST['email'];
$mdp = $_POST['mdp'];
$admin = "";
$hash = hash('sha512', $mdp);
// Préparation de la requête
$dbh = connectDB();
$connexion = $dbh->prepare('SELECT * fROM users WHERE email = :email AND password = :password');
// Execution de la requête
$connexion->execute([
":email" => $email,
":password" => $hash,
]);
// Récupération du résultat
$results = $connexion->fetchAll();
$dbh = connectDB();
$connexion = $dbh->prepare('SELECT password = :password from users');
$connexion->execute([
":password" => $password,
]);
$resultpass = $connexion->fetchAll();
if($resultpass != $hash){
$errors[] = 'Mot de passe incorect';
}
if(!empty($results)){
$_SESSION['user'] = $results[0];
} else {
$_SESSION['user'] = null;
}
}
?>
<?php if(empty($_SESSION['user'])) {?>
<form class="formconnexion" method="POST">
<div class="form-group">
<label class="email">Email</label>
<input type="email" class="form-control" name="email">
</div>
<div class="form-group">
<label class="mdp">Password</label>
<input type="password" class="form-control" name="mdp">
</div>
<button class="btn btn-primary">Valider</button>
</form>
<?php if (!empty($errors)) {
echo '<div class="alert alert-danger mt-4" role="alert">';
echo implode ("<br>", $errors);
echo '</div>';
} ?>
<?php } else { ?>
<?php header('location:index.php'); ?>
<?php }?>