<?php
session_start();
include('./log/config.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password'];

    // Hent brugeroplysninger fra databasen
    $sql = "SELECT * FROM users WHERE username='$username'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        $user = $result->fetch_assoc();

        // Verificer password
        if (password_verify($password, $user['password'])) {
            $_SESSION['user_id'] = $user['id'];
            $_SESSION['username'] = $user['username'];
            header('Location: input.php'); // Redirect til dashboard
        } else {
            echo "Forkert adgangskode";
        }
    } else {
        echo "Brugeren findes ikke";
    }
}

$conn->close();
?>

<!DOCTYPE html>
<html lang="da">
<head>
	<style>
	html, body {
	width: 100%;
	height: 100%;
	margin: 0;
	background-color: #ADD8E6;
	background-image: linear-gradient(#BFBFBF, #E5E5E5);
	font-family: Sans-Serif;
	color: #333333;
	text-decoration: none;

}

#main  {
	margin: auto;
	width: 50%;
	max-width: 600px;
	background-color: #ffffff;
	padding: 20px 20px 20px 20px;
	border-radius: 8px;
	line-height: 1.5em;
	margin-bottom: 20px;
	margin-top: 20px;
}
	</style>
	
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<link rel="icon" href="https://rpix.dk/tracking/favicon.svg">
    <title>Login</title>
</head>
<body>
	<div id="main">
    <h2>Login</h2>
    <form method="POST" action="login.php">
        <label for="username">Brugernavn:</label><br>
        <input type="text" id="username" name="username" required><br>
        <label for="password">Adgangskode:</label><br>
        <input type="password" id="password" name="password" required><br><br>
        <input type="submit" value="Login">
    </form>
    </div>
    
</body>
</html>



