-
Notifications
You must be signed in to change notification settings - Fork 2
/
login.php
43 lines (41 loc) · 1.23 KB
/
login.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
<?php
require ('config.php');
session_start();
if (isset($_POST['username']) & isset($_POST['password'])){
try {
$sth = $conn->prepare("SELECT * FROM user WHERE username=:username");
$sth->bindParam(':username', $_POST['username']);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
$hash = $row['password'];
if (password_verify($_POST['password'], $hash)){
$_SESSION['id'] = $row['id'];
$_SESSION['username'] = $row['username'];
header('Location: index.php');
}else{
echo "Mauvais mot de passe our username.";
}
}catch (PDOException $e){
print "Erreur !: " . $e->getMessage() . "<br/>";
}
}else{
echo "";
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connexion</title>
</head>
<body>
<form action="" method ="POST">
<a>Username</a>
<input type="text" placeolder="Username" name="username"></input>
<a>Password</a>
<input type="password" placeolder="Password" name="password"></input>
<button type="submit" >Connexion</button>
</form>
</body>
</html>