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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
<?php
/* error_reporting(E_ALL);
ini_set('display_errors', 1); */
session_start();
if (isset($_POST['abmelden'])) unset($_SESSION['benutzer']);
$benutzername = $_POST['input_benutzername'];
$passwort = $_POST['input_passwort'];
$datenbank = new mysqli('localhost', 'root', 'sexyweyer', 'Annapurna');
if ($_POST['abmelden_loeschen'] == 'abmelden') {
unset($_SESSION['benutzer']);
} elseif ($_POST['abmelden_loeschen'] == 'loeschen') {
$benutzer = $_SESSION['benutzer'];
$datenbank->query("DELETE FROM benutzer WHERE benutzer_id = '$benutzer'");
unset($_SESSION['benutzer']);
}
if (isset($_POST['konto_loeschen'])) {
$datenbank->query("DELETE FROM benutzer WHERE benutzer_id = '{$_SESSION['benutzer']}'");
}
if ($_POST['login'] == 'anmeldung') {
$statement = $datenbank->prepare("SELECT * FROM benutzer WHERE benutzername = ?");
$statement->bind_param('s', $benutzername);
$statement->execute();
$result = $statement->get_result();
$statement->close();
if ($user = $result->fetch_assoc()) {
if (password_verify($passwort, $user['passwort'])) {
$_SESSION['benutzer'] = $user['benutzer_id'];
} else {
$nachricht = "Passwort ist falsch!";
}
} else {
$nachricht = "Benutzername nicht registriert!";
}
} else if ($_POST['login'] == 'registrierung') {
if (str_contains($benutzername, ' ')) {
$nachricht = "Benutzername darf keine Leerzeichen enthalten!";
} else if (str_contains($passwort, ' ')) {
$nachricht = "Passwort darf keine Leerzeichen enthalten!";
} else if (!preg_match('/[^a-zA-Z0-9]/', $passwort)) {
$nachricht = "Passwort muss ein Sonderzeichen enthalten!";
}
$statement = $datenbank->prepare("SELECT * FROM benutzer WHERE benutzername = ?");
$statement->bind_param('s', $benutzername);
$statement->execute();
$result = $statement->get_result();
if ($result->num_rows) {
$nachricht = "Benutzername ist schon registriert!";
} else {
$passwort_hash = password_hash($passwort, PASSWORD_DEFAULT);
$statement = $datenbank->prepare(
"INSERT INTO benutzer (benutzername, passwort, letzter_login)
VALUES (?, ?, NOW())"
);
$statement->bind_param('ss', $benutzername, $passwort_hash);
if ($statement->execute()) {
$nachricht = "Benutzer wurde erfolgreich registriert!";
} else {
$nachricht = "Fehler bei der Registrierung(" . $statement->errno . "): " . $statement->error;
}
}
$statement->close();
}
$datenbank->close();
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link rel="icon" type="image/x-icon" href="/style/avocado.png">
<link rel="stylesheet" type="text/css" href="/style/style.css">
</head>
<body>
<nav class="medium_box">
<ul class="hor_spacing">
<li class="hor_spacing_item">
<a class="small_box tertiary_color_style" href="/login">Login</a>
</li>
<li class="hor_spacing_item">
<a class="small_box color_inverse_on_hover" href="/kalorien_rechner">Kalorien-rechner</a>
</li>
<li class="hor_spacing_item">
<a class="small_box color_inverse_on_hover" href="/kalorien_zaehler">Kalorien-zähler</a>
</li>
<li class="hor_spacing_item">
<a class="small_box color_inverse_on_hover" href="/rezepte">Rezepte</a>
</li>
<li class="hor_spacing_item">
<a class="small_box color_inverse_on_hover" href="/workouts">Workouts</a>
</li>
</ul>
</nav>
<main class="big_box hor_spacing">
<h1>Anmeldung / Registrierung</h1>
<?php if (isset($_SESSION['benutzer'])) { ?>
<div class="medium_box">
<h2>Sie sind eingeloggt!</h2>
<form class="flexbox" action="" method="POST">
<button class="small_box color_inverse_on_hover" style="flex: 1" type="submit" name="abmelden_loeschen" value="abmelden"><h2 style="margin: 0">Abmelden</h2></button>
<button class="small_box color_inverse_on_hover" style="flex: 1" type="submit" name="abmelden_loeschen" value="loeschen"><h2 style="margin: 0">Konto löschen</h2></button>
</form>
</div>
<?php } else {
?>
<form class="hor_spacing_item" method="POST" action="">
<ol style="list-style-position: inside">
<p><li>Benutzername und Passwort dürfen keine Leerzeichen enthalten.</li></p>
<p><li>Das Passwort muss mindestens ein Sonderzeichen enthalten.</li></p>
<p><li>Benutzername und Passwort dürfen nicht weniger als 8 und mehr als 24 Charaktere enthalten.</li></p>
<p><li>Durch die Registrierung akzeptieren Sie die <a href="/agb.html" style="text-decoration: underline">AGBs</a></li></p>
</ol>
<br>
<div class="flexbox hor_spacing_item">
<div class="medium_box" style="flex: 1">
<h2>Benutzername: </h2>
<input class="small_box color_inverse_on_hover" type="text" minlength="8" maxlength="24" name="input_benutzername" required>
</div>
<div class="medium_box" style="flex: 1">
<h2>Passwort: </h2>
<input class="small_box color_inverse_on_hover" type="password" minlength="8" maxlengh="24" name="input_passwort" required>
</div>
</div>
<div class="flexbox hor_spacing_item">
<button class="medium_box color_inverse_on_hover" style="flex: 1" type="submit" name="login" value="anmeldung"><h2 style="margin: 0">ANMELDEN</h2></button>
<button class="medium_box color_inverse_on_hover" style="flex: 1" type="submit" name="login" value="registrierung"><h2 style="margin: 0">REGISTRIEREN</h2></button>
</div>
</form>
<?php if ($nachricht) { ?>
<div class="medium_box hor_spacing_item"><h2><?= $nachricht ?></h2></div>
<?php }
} ?>
</main>
</body>
</html>
|