-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
86 lines (69 loc) · 3.05 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
session_start();
include 'config/connection.php';
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Check the username and password
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST['username']);
$entered_password = mysqli_real_escape_string($conn, $_POST['password']);
$query = mysqli_query($conn, "SELECT * FROM users WHERE username = '$username'");
if (mysqli_num_rows($query) > 0) {
$row = mysqli_fetch_assoc($query);
$stored_password = $row['password'];
// Verify the entered password against the stored hash
if (password_verify($entered_password, $stored_password)) {
$_SESSION['user'] = $username;
$account_type = $row['account_type'];
// Redirect based on account type
if ($account_type == 'admin') {
header("location: admin/dashboard.php"); // Redirect to admin page
$_SESSION['account_type'] = $account_type;
} elseif ($account_type == 'staff') {
header("location: staff/dashboard.php"); // Redirect to staff page
$_SESSION['account_type'] = $account_type;
} else {
header("location: index.php"); // Redirect to default page if account type is neither admin nor staff
}
exit();
} else {
echo '<script>alert("Incorrect Password!");</script>';
}
} else {
echo '<script>alert("Incorrect username!");</script>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" href="styles/index.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Zen+Kaku+Gothic+Antique%3A400%2C700"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro%3A400%2C700"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins%3A400"/>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container">
<div class="main-card">
<h2>SEAT AND SIP CAFE</h2>
<hr class="line">
<form action="index.php" method="POST" class="log">
<div class="input-box">
<label for="username" >Enter Username: </label>
<input id="username" type="text" name="username" required="required" placeholder="Username"/>
</div>
<div class="input-box">
<label for="pass">Enter Password:</label>
<input id="pass" type="password" name="password" required="required" placeholder="Password"/>
</div>
<input type="submit" value="Log-in" name="login" class="btn">
</form>
</div>
</div>
</body>
</html>