Files
portfoliowai/admin/login.php
T

149 lines
4.5 KiB
PHP

<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Redirect if already logged in
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
header("Location: dashboard.php");
exit();
}
require_once __DIR__ . '/../config/db.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = trim($_POST['password'] ?? '');
if (!empty($username) && !empty($password)) {
$stmt = $mysqli->prepare("SELECT * FROM admin WHERE username = ?");
if ($stmt) {
$stmt->bind_param("s", $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result && $result->num_rows > 0) {
$user = $result->fetch_assoc();
if (password_verify($password, $user['password'])) {
// Login successful
$_SESSION['admin_logged_in'] = true;
$_SESSION['admin_username'] = $user['username'];
header("Location: dashboard.php");
exit();
}
}
$error = 'Invalid username or password.';
$stmt->close();
} else {
$error = 'Database error. Please try again.';
}
} else {
$error = 'Please enter both username and password.';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login | Portfolio</title>
<link rel="stylesheet" href="../assets/css/style.css">
<style>
.login-wrapper {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 20px;
background: #090d16;
}
.login-card {
background: rgba(30, 41, 59, 0.4);
border: 1px solid rgba(148, 163, 184, 0.12);
border-radius: 16px;
padding: 40px;
width: 100%;
max-width: 400px;
backdrop-filter: blur(10px);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}
.login-card h2 {
font-family: 'Outfit', sans-serif;
font-size: 1.8rem;
font-weight: 800;
color: #f8fafc;
margin-bottom: 8px;
text-align: center;
}
.login-card p.subtitle {
color: #94a3b8;
font-size: 0.9rem;
text-align: center;
margin-bottom: 24px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
color: #f8fafc;
font-size: 0.85rem;
font-weight: 600;
margin-bottom: 6px;
}
.error-message {
color: #ef4444;
background: rgba(239, 68, 68, 0.1);
border: 1px solid rgba(239, 68, 68, 0.25);
padding: 10px;
border-radius: 8px;
font-size: 0.85rem;
margin-bottom: 20px;
text-align: center;
}
.back-home {
display: block;
text-align: center;
margin-top: 20px;
color: #64748b;
text-decoration: none;
font-size: 0.85rem;
transition: color 0.2s;
}
.back-home:hover {
color: #3b82f6;
}
</style>
</head>
<body class="login-wrapper">
<div class="login-card">
<h2>Admin Panel</h2>
<p class="subtitle">Enter your credentials to continue</p>
<?php if (!empty($error)): ?>
<div class="error-message"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form action="login.php" method="POST">
<div class="form-group">
<label for="username">Username</label>
<input type="text" name="username" id="username" placeholder="admin" required autocomplete="username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" id="password" placeholder="••••••••" required autocomplete="current-password">
</div>
<button type="submit" class="btn primary full-width">Login</button>
</form>
<a href="../index.php" class="back-home">← Back to Portfolio</a>
</div>
</body>
</html>