120 lines
3.6 KiB
PHP
120 lines
3.6 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!";
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
|
|
rel="stylesheet">
|
|
<title>Login Seite</title>
|
|
<link rel="stylesheet" href="styles.css">
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<form class="login-form" action="" method="post">
|
|
<h2>Login</h2>
|
|
|
|
<div class="error"><?php echo $error; ?></div>
|
|
|
|
|
|
<div class="input-group">
|
|
<label for="username">Benutzername</label>
|
|
<input type="text" id="username" name="benutzername" required>
|
|
</div>
|
|
<div class="input-group">
|
|
<label for="password">Passwort</label>
|
|
<div class="password_show">
|
|
<input type="password" id="password" name="passwort" required>
|
|
<span class="material-icons toggle-password" id="togglePassword">
|
|
visibility_off
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="input-group checkbox">
|
|
<input type="checkbox" id="eingeloggt_bleiben" name="eingeloggt_bleiben">
|
|
<label for="eingeloggt_bleiben">Eingeloggt bleiben</label>
|
|
</div>
|
|
<div class="actions">
|
|
<button type="submit">Anmelden</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|
|
<script>
|
|
document.getElementById('togglePassword').addEventListener('click', function (e) {
|
|
const passwordInput = document.getElementById('password');
|
|
const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
|
|
passwordInput.setAttribute('type', type);
|
|
this.textContent = type === 'password' ? 'visibility_off' : 'visibility';
|
|
});
|
|
|
|
</script>
|