forked from SkyyInfinity/Projet-Vaccination-NFactory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnexion.php
82 lines (70 loc) · 2.51 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// Connexion
session_start();
include('inc/pdo.php');
include('inc/functions.php');
$title = 'Connexion';
$errors = array();
// if soumis
if (!empty($_POST['submitted'])) {
// Faille
$email = cleanXss($_POST['email']);
$password = cleanXss($_POST['password']);
if(!empty($email) && !empty($password)) {
// request
$sql = "SELECT * FROM users WHERE email = :email OR password = :password";
$query = $pdo->prepare($sql);
$query->bindValue(':email',$email,PDO::PARAM_STR);
$query->bindValue(':password',$password,PDO::PARAM_STR);
$query->execute();
$user = $query->fetch();
if (!empty($user)) {
if (password_verify($password, $user['password'])) {
// connexion possible
$_SESSION['user'] = array(
'id' => $user['id'],
'nom' => $user['nom'],
'prenom' => $user['prenom'],
'email' => $user['email'],
'role' => $user['role'],
'ip' => $_SERVER['REMOTE_ADDR']
);
header('Location: index.php');
} else {
$errors['password'] = 'Le mot de passe est incorrect.';
}
}else {
$errors['password'] = 'Une erreur est survenue, veuillez réessayer.';
}
} else {
$errors['password'] = 'Veuillez renseigner les champs.';
}
}
include('inc/header.php');?>
<section class="connexion-content">
<div class="wrap">
<h2>Connexion</h2>
<hr>
<form id="formconnex" action="" method="post">
<!-- EMAIL -->
<div class="box-form">
<!-- <label for="mail">E-mail<span>*</span></label> -->
<input placeholder=" Adresse Email" type="email" name="email" id="mail" value="<?php if (!empty($_POST['email'])){echo $_POST['email'];} ?>">
<span class="error"><?php if (!empty($errors['email'])){echo $errors['email'];} ?></span>
</div>
<!-- MOT DE PASSE -->
<div class="box-form">
<!-- <label for="mdp">Mot de passe<span>*</span></label> -->
<input placeholder=" Mot de passe" type="password" name="password" id="mdp" value="<?php if (!empty($_POST['password'])){echo $_POST['password'];} ?>">
<span class="error"><?php if (!empty($errors['password'])){echo $errors['password'];} ?></span>
</div>
<!-- MDP OUBLIE -->
<div class="btn-forgot">
<a href="forgotPassword.php">Mot de passe oublié</a>
</div>
<!-- SUBMIT -->
<input class="btn-contrast" type="submit" name="submitted" value="Se connecter">
</form>
</div>
</section>
<?php include('inc/footer.php');