CoolFace
Apppublic

starinfolab/codecraft-conductor-wizard

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
login.php74 linesDownload Raw Back to admin
1```php2<?php3session_start();4 5// Database connection6$db = new mysqli('localhost', 'root', '', 'portfolio_db');7if ($db->connect_error) {8    die("Connection failed: " . $db->connect_error);9}10 11// Handle login12if ($_SERVER['REQUEST_METHOD'] == 'POST') {13    $username = $db->real_escape_string($_POST['username']);14    $password = $db->real_escape_string($_POST['password']);15    16    $sql = "SELECT id, password FROM admin_users WHERE username = '$username'";17    $result = $db->query($sql);18    19    if ($result->num_rows == 1) {20        $user = $result->fetch_assoc();21        if (password_verify($password, $user['password'])) {22            $_SESSION['admin_logged_in'] = true;23            $_SESSION['admin_user_id'] = $user['id'];24            header('Location: dashboard.php');25            exit;26        }27    }28    $error = "Invalid username or password";29}30?>31 32<!DOCTYPE html>33<html lang="en">34<head>35    <meta charset="UTF-8">36    <meta name="viewport" content="width=device-width, initial-scale=1.0">37    <title>Admin Login</title>38    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">39    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>40</head>41<body class="bg-gray-100 h-screen flex items-center justify-center">42    <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md">43        <div class="text-center mb-8">44            <h1 class="text-3xl font-bold text-gray-800">Admin Login</h1>45            <p class="text-gray-600">Access your dashboard</p>46        </div>47        48        <?php if (isset($error)): ?>49            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">50                <?php echo $error; ?>51            </div>52        <?php endif; ?>53 54        <form method="POST">55            <div class="mb-4">56                <label class="block text-gray-700 mb-2" for="username">Username</label>57                <input type="text" id="username" name="username" 58                       class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-teal-500" required>59            </div>60            <div class="mb-6">61                <label class="block text-gray-700 mb-2" for="password">Password</label>62                <input type="password" id="password" name="password" 63                       class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-teal-500" required>64            </div>65            <button type="submit" 66                    class="w-full bg-teal-600 hover:bg-teal-700 text-white py-2 px-4 rounded-lg transition duration-200">67                Login68            </button>69        </form>70    </div>71    <script>feather.replace();</script>72</body>73</html>74```