73 lines
2.8 KiB
PHP
73 lines
2.8 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
// If user is already logged in, redirect to dashboard
|
|
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
}
|
|
|
|
// Hardcoded credentials
|
|
define('USERNAME', 'student');
|
|
define('PASSWORD', 'password123');
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$username = $_POST['username'] ?? '';
|
|
$password = $_POST['password'] ?? '';
|
|
|
|
if ($username === USERNAME && $password === PASSWORD) {
|
|
$_SESSION['loggedin'] = true;
|
|
$_SESSION['username'] = $username;
|
|
header('Location: dashboard.php');
|
|
exit;
|
|
} else {
|
|
$error = 'Invalid username or password.';
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - University Management</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-6 col-lg-4" style="margin-top: 100px;">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h3 class="card-title text-center mb-4">Student Login</h3>
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
<form action="login.php" method="POST">
|
|
<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 class="text-center mt-3">
|
|
<p class="text-muted">Use `student` / `password123` to log in.</p>
|
|
<a href="index.php">Back to Home</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|