TKK_E32222855/login.php

109 lines
3.8 KiB
PHP

<?php
session_start();
include "koneksi.php";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST['username'];
$password = $_POST['password']; // gunakan hash jika perlu
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) == 1) {
$_SESSION['username'] = $username;
header("Location: index.php");
exit();
} else {
$error = "Username atau password salah.";
}
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<title>Login - Absensi RFID</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
background: linear-gradient(135deg, #0d6efd, #6f42c1);
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.login-card {
background: white;
padding: 30px;
border-radius: 16px;
box-shadow: 0 10px 25px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
.logo {
width: 80px;
height: 80px;
margin-bottom: 15px;
}
</style>
</head>
<body>
<div class="login-card text-center">
<img src="https://cdn-icons-png.flaticon.com/512/3064/3064197.png" class="logo" alt="Logo">
<h4 class="mb-4">Sistem Absensi RFID</h4>
<?php if (isset($error)) : ?>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="bi bi-exclamation-circle"></i> <?php echo $error; ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<form method="POST" class="text-start">
<div class="mb-3">
<label class="form-label">Username</label>
<div class="input-group">
<span class="input-group-text"><i class="bi bi-person-fill"></i></span>
<input type="text" name="username" class="form-control" placeholder="Masukkan username" required>
</div>
</div>
<div class="mb-3 position-relative">
<label class="form-label">Password</label>
<div class="input-group">
<span class="input-group-text"><i class="bi bi-lock-fill"></i></span>
<input type="password" name="password" id="password" class="form-control" placeholder="Masukkan password" required>
<span class="input-group-text" onclick="togglePassword()" style="cursor: pointer;">
<i class="bi bi-eye-fill" id="eyeIcon"></i>
</span>
</div>
</div>
<button type="submit" class="btn btn-primary w-100 mt-3">Login</button>
</form>
<p class="mt-4 text-muted" style="font-size: 0.9em;">&copy; <?php echo date('Y'); ?> Sistem Absensi RFID</p>
</div>
<script>
function togglePassword() {
const passwordInput = document.getElementById("password");
const eyeIcon = document.getElementById("eyeIcon");
if (passwordInput.type === "password") {
passwordInput.type = "text";
eyeIcon.classList.remove("bi-eye-fill");
eyeIcon.classList.add("bi-eye-slash-fill");
} else {
passwordInput.type = "password";
eyeIcon.classList.remove("bi-eye-slash-fill");
eyeIcon.classList.add("bi-eye-fill");
}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>