This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
72 lines (59 loc) · 2.34 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
61
62
63
64
65
66
67
68
69
70
71
72
<?php
session_start();
require_once("templates/config.inc.php");
require_once("templates/functions.inc.php");
$error_msg = "";
if(isset($_POST['email']) && isset($_POST['passwort'])) {
$email = $_POST['email'];
$passwort = $_POST['passwort'];
$statement = $pdo->prepare("SELECT * FROM users WHERE email = :email");
$result = $statement->execute(array('email' => $email));
$user = $statement->fetch();
//Überprüfung des Passworts
if ($user !== false && password_verify($passwort, $user['passwort'])) {
$_SESSION['userid'] = $user['id'];
//Möchte der Nutzer angemeldet beleiben?
if(isset($_POST['angemeldet_bleiben'])) {
$identifier = random_string();
$securitytoken = random_string();
$insert = $pdo->prepare("INSERT INTO securitytokens (user_id, identifier, securitytoken) VALUES (:user_id, :identifier, :securitytoken)");
$insert->execute(array('user_id' => $user['id'], 'identifier' => $identifier, 'securitytoken' => sha1($securitytoken)));
setcookie("identifier",$identifier,time()+(3600*24*365)); //Valid for 1 year
setcookie("securitytoken",$securitytoken,time()+(3600*24*365)); //Valid for 1 year
}
header("location: daten.php");
exit;
} else {
$error_msg = "E-Mail oder Passwort war ungültig<br><br>";
}
}
$email_value = "";
if(isset($_POST['email']))
$email_value = htmlentities($_POST['email']);
include("templates/header.inc.php");
?>
<div class="container small-container-330 form-signin">
<form action="login.php" method="post">
<h2 class="form-signin-heading">Login</h2>
<?php
if(isset($error_msg) && !empty($error_msg)) {
echo $error_msg;
}
?>
<label for="inputEmail" class="sr-only">E-Mail</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="E-Mail" value="<?php echo $email_value; ?>" required autofocus>
<label for="inputPassword" class="sr-only">Passwort</label>
<input type="password" name="passwort" id="inputPassword" class="form-control" placeholder="Passwort" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me" name="angemeldet_bleiben" value="1" checked> Angemeldet bleiben
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Login</button>
<br>
<a href="passwortvergessen.php">Passwort vergessen</a>
</form>
</div> <!-- /container -->
<?php
include("templates/footer.inc.php")
?>