FSCash/html/login.php
2026-01-05 14:38:43 +01:00

53 lines
1.3 KiB
PHP

<?php
// login.php
require 'config.php';
// Verbindung herstellen
$conn = new mysqli($host, $user, $pass, $db);
// Verbindung prüfen
if ($conn->connect_error) {
die("Verbindung fehlgeschlagen: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$input_username = $_POST['username'];
$input_password = $_POST['password'];
$sql = "SELECT id, username, password FROM users WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $input_username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
if (password_verify($input_password, $row['password'])) {
echo "Login erfolgreich! Willkommen, " . htmlspecialchars($row['username']);
} else {
echo "Falsches Passwort!";
}
} else {
echo "Benutzer nicht gefunden!";
}
$stmt->close();
}
$conn->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form method="post" action="login.php">
Username: <input type="text" name="username" required><br>
Passwort: <input type="password" name="password" required><br>
<input type="submit" value="Login">
</form>
</body>
</html>