update: DB-Login
This commit is contained in:
1 parent
1bf7f87e4f
commit
aab098ff5e
1 file changed
+29
-13
+29
-13
@@ -1,31 +1,47 @@
|
||||
<?php
|
||||
// Vor allen includes, vor jeglicher Ausgabe
|
||||
include_once 'controller/DatabaseController.php';
|
||||
|
||||
session_set_cookie_params([
|
||||
'lifetime' => 0, // bis Browser geschlossen
|
||||
'path' => '/', // Gültig für ganze Domain
|
||||
'domain' => '', // aktuelle Domain
|
||||
'secure' => false, // true nur für HTTPS
|
||||
'lifetime' => 0,
|
||||
'path' => '/',
|
||||
'domain' => '',
|
||||
'secure' => false,
|
||||
'httponly' => true,
|
||||
'samesite' => 'Lax'
|
||||
]);
|
||||
session_start();
|
||||
|
||||
|
||||
$error = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
// Beispiel: feste Zugangsdaten
|
||||
if ($username === 'admin' && $password === 'secret') {
|
||||
$_SESSION['user_logged_in'] = true;
|
||||
$_SESSION['username'] = $username;
|
||||
$results = DatabaseShow(
|
||||
'Benutzer',
|
||||
'PASSWORD',
|
||||
'NAME = ?',
|
||||
$username
|
||||
);
|
||||
|
||||
if (!empty($results)) {
|
||||
$user = $results[0];
|
||||
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
if (isset($user['PASSWORD'])) {
|
||||
if (password_verify($password, $user['PASSWORD'])) {
|
||||
$_SESSION['user_logged_in'] = true;
|
||||
$_SESSION['username'] = $username;
|
||||
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Login fehlgeschlagen: Passwort inkorrekt';
|
||||
}
|
||||
} else {
|
||||
$error = 'Systemfehler: Spalte "password" nicht in der Datenbank gefunden.';
|
||||
}
|
||||
} else {
|
||||
$error = 'Login fehlgeschlagen';
|
||||
$error = 'Login fehlgeschlagen: Benutzer nicht gefunden';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in new issue
Block a user