Files
kfz-php-tool/login.php
2025-08-02 13:10:21 +02:00

98 lines
3.0 KiB
PHP

<?php
include("config/config.php");
session_start();
if(isset($_SESSION['login_user'])){
header("location:dashboard.php");
die();
}
if(isset($_COOKIE['eingeloggt_bleiben']) && !isset($_SESSION["login_user"])) {
$user = json_decode($_COOKIE['eingeloggt_bleiben'], true);
$ses_sql = mysqli_query($db,"select username from admin where username = '$user[username]' and passcode = '$user[password]'");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$count = mysqli_num_rows($ses_sql);
if ($count == 1) {
$login_session = $user['username'];
$_SESSION['login_user'] = $login_session;
header("location: dashboard.php");
die();
}else {
setcookie('eingeloggt_bleiben', '', 1);
}
}
$error = "";
if($_SERVER["REQUEST_METHOD"] == "POST") {
// username and password sent from form
$myusername = mysqli_real_escape_string($db,$_POST['benutzername']);
$mypassword = mysqli_real_escape_string($db,$_POST['passwort']);
//$mypassword = md5($mypassword);
$mypassword = hash_hmac('md5', $mypassword, $secretKey);
$sql = "SELECT * FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
//$active = $row['active'];
$count = mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count == 1) {
$_SESSION['login_user'] = $myusername;
if ($_POST['eingeloggt_bleiben'] == true) {
setcookie('eingeloggt_bleiben', json_encode([
'username' => $myusername,
'password' => $mypassword
]), time() + 3600 * 24 * 30);
}
header("location: dashboard.php");
}else {
$error = "Benutzername oder Password falsch!";
}
}
?>
<html>
<link rel="stylesheet" href="css/login.css">
<meta name="viewport" content=" initial-scale=0, maximum-scale=0, user-scalable=0"/>
<link rel="apple-touch-icon" href="favicon.ico"/>
<link rel="manifest" href="manifest.json">
<script src="sw.js" defer></script>
<script src="install.js" defer></script>
<head>
<title>Login Page</title>
</head>
<body>
<div class="box_33">
<div class="header_bild_div"><img src="<?php echo $header_login_image;?>"></div>
<label class="box_label">Login</label>
<form action="" method="post">
<input class="box_input" placeholder="Benutzername" type="text" name="benutzername">
<input class="box_input" placeholder="Passwort" type="password" name="passwort">
<div style="display: flex; justify-content: flex-end">
<input class="box_input" type="checkbox" name="eingeloggt_bleiben" id="eingeloggt_bleiben" style="float: left; width: auto"><label class="label_eingeloggt_bleiben" for="eingeloggt_bleiben">Eingeloggt bleiben</label></input>
</div>
<input class="button" style="display: block; margin:auto" type="submit" value="Einloggen"/>
<div class="error"><?php echo $error; ?></div>
</form>
</div>
</body>
</html>