-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
60 lines (46 loc) · 1.37 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_GET['login'])) {
$email = $_POST['email'];
$password = $_POST['password'];
$statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$result = $statement->execute(['email' => $email]);
$user = $statement->fetch();
//Überprüfung des Passworts
if ($user !== false && password_verify($password, $user['password'])) {
$_SESSION['userid'] = $user['id'];
} else {
$errorMessage = "wrong email or password<br>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
if (isset($errorMessage)) {
echo $errorMessage;
}
?>
<div id="login" class="overlay">
<a href="#" class="closebtn" id="hideLogin">×</a>
<div class="overlay-content">
<form action="?login=1" method="post">
<input type="email" name="email" placeholder="email" maxlength="250"/><br>
<input type="password" name="password" placeholder="Password" maxlength="250"/>
<input type="hidden" name="csrf" value="'.$_SESSION['csrf_token'].'"><br>
<button id="loginButton2">Login</button>
</form>
</div>
</div>
</body>
</html>
/*
+----+----+----+
|just|like|that|
+----+----+----+
*/