-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
90 lines (87 loc) · 3.29 KB
/
index.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
83
84
85
86
87
88
89
90
<?php
require_once('functions.php');
session_start();
$user = $_SESSION['user'] ?: null;
$captchaError = '';
$db = connectDb();
if(isset($_POST['captcha'])) {
if ($_POST['captcha'] == $_SESSION['captcha']) {
echo "Captcha valide !";
if (isset($_POST['email']) && isset($_POST['password'])) {
//if (!empty($_POST['email']) && !empty($_POST['password'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$q = $db->prepare('SELECT * FROM users WHERE email= :email');
$q->bindValue('email', $email);
$q->execute();
$res = $q->fetch(PDO::FETCH_ASSOC);
if($res){
$passwordHash = $res['password'];
if(password_verify($password,$passwordHash)){
//var_dump($password);
//var_dump($passwordHash);
echo "Connexion établie";
$users = logUser($_POST['email'], $_POST['password']);
if(!empty($users)) {
$user = $users[0];
$_SESSION['user'] = $user;
}
}
else{
echo "Mauvais Mot De Passe !!";
}
}else{
echo "Mauvais Mail/Mot De Passe !!";
}
}
} else {
$captchaError = "Captcha Invalide !";
}
}
?>
<html>
<head>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ma super app sécurisée</title>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
crossorigin="anonymous">
<a href="logout.php">Log Out Btn</a>
<a href="register.php">S'enregistrer</a>
</head>
</head>
<body>
<div class="container">
<?php if(!$user): ?>
<h1>Connexion</h1>
<form action="/" method="POST">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input name="email" type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small >
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input name="password" type="password" class="form-control" id="exampleInputPassword1">
</div>
<div class="form-group">
<label for="stayConnected">Rester connecté</label>
<input name="stayConnected" type="checkbox" id="stayConnected">
</div>
<img src="captcha.php" />
<input type="text" name="captcha" />
<?= $captchaError ?>
<!-- <input type="submit" /> -->
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<?php else: ?>
<h1>Bienvenue <?= $user->email ?></h1>
<a href="informations.php?id=<?= $user->id ?>">Mes informations</a>
<?php endif ?>
</div>
</body>
</html>