1<?php
2session_start();
3$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', '');
4
5if(isset($_GET['login'])) {
6 $email = $_POST['email'];
7 $passwort = $_POST['passwort'];
8
9 $statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
10 $result = $statement->execute(array('email' => $email));
11 $user = $statement->fetch();
12
13 //Überprüfung des Passworts
14 if ($user !== false && password_verify($passwort, $user['passwort'])) {
15 $_SESSION['userid'] = $user['id'];
16 die('Login erfolgreich. Weiter zu <a href="geheim.php">internen Bereich</a>');
17 } else {
18 $errorMessage = "E-Mail oder Passwort war ungültig<br>";
19 }
20
21}
22?>
23<!DOCTYPE html>
24<html>
25<head>
26 <title>Login</title>
27</head>
28<body>
29
30<?php
31if(isset($errorMessage)) {
32 echo $errorMessage;
33}
34?>
35
36<form action="?login=1" method="post">
37E-Mail:<br>
38<input type="email" size="40" maxlength="250" name="email"><br><br>
39
40Dein Passwort:<br>
41<input type="password" size="40" maxlength="250" name="passwort"><br>
42
43<input type="submit" value="Abschicken">
44</form>
45</body>
46</html>
47
1<?php
2session_start();
3?>
4<!DOCTYPE html>
5<html lang="en">
6<head>
7 <meta charset="UTF-8">
8 <meta name="viewport" content="width=device-width, initial-scale=1.0">
9 <title>Login</title>
10</head>
11<body>
12 <form action="" method="POST">
13 <input type="password" name="password">
14 <button type="submit" name="submit">Login</button>
15 </form>
16 <?php
17 if(isset($_POST['submit'])){
18 if(password_verify($_POST['password'], '$2y$10$sejeRNYZGaoPh1EwfcuO1.hxl/uepQOh9SITWWgeej86vnMt26KIa')){
19 $_SESSION['login'] = true;
20 header("Location: http://localhost");
21 }
22 }
23?>
24</body>
25</html>