35573-vm/admin/index.php
2025-11-08 15:26:25 +00:00

64 lines
2.3 KiB
PHP

<?php
session_start();
require_once '../db/config.php';
$error = '';
// Hardcoded admin credentials
define('ADMIN_USER', 'admin');
define('ADMIN_PASS', 'password'); // In a real application, use a hashed password
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if ($username === ADMIN_USER && $password === ADMIN_PASS) {
$_SESSION['admin_logged_in'] = true;
header('Location: dashboard.php');
exit;
} else {
$error = 'Invalid username or password.';
}
}
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
header('Location: dashboard.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login - Smart Farmer</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head>
<body>
<div class="container vh-100 d-flex justify-content-center align-items-center">
<div class="card shadow" style="width: 22rem;">
<div class="card-body p-5">
<h3 class="card-title text-center mb-4">Admin Login</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="POST" action="index.php">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>