-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
181 lines (157 loc) · 7.16 KB
/
index.php
File metadata and controls
181 lines (157 loc) · 7.16 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
// Include the database connection
include("database.php");
$login = '';
$password = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check if 'login' and 'password' are set in the POST request
if (isset($_POST['login']) && isset($_POST['password'])) {
$login = $_POST['login'];
$password = $_POST['password'];
// Check if both fields are filled
if (!empty($login) && !empty($password)) {
// Prepare SQL query to check for email, username, or phone number
$sql = "SELECT CustomerID, FirstName, LastName, Username, Password FROM customers WHERE Email = ? OR Username = ? OR Phone = ? LIMIT 1";
$stmt = mysqli_prepare($connect, $sql);
mysqli_stmt_bind_param($stmt, "sss", $login, $login, $login);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$user = mysqli_fetch_assoc($result);
// Hash the user-provided password using SHA-256
$hashed_password = hash('sha256', $password);
// Verify the hashed password
if ($user && $hashed_password === $user['Password']) {
// Set session variables for the logged-in user
session_start(); // Start session
$_SESSION['user_id'] = $user['CustomerID'];
$_SESSION['username'] = $user['Username'];
$_SESSION['first_name'] = $user['FirstName'];
$_SESSION['last_name'] = $user['LastName'];
echo '
<div class="loading-screen">
<div class="log-in">Logging in</div>
<div class="loading-image">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Loading Image">
</div>
</div>
<style>
.loading-screen {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(#E7E7E7, #818181, #9A9B84);
background-size: cover;
background-position: center;
background-repeat: no-repeat;
color: black;
text-align: center;
font-size: 50px;
z-index: 1000;
}
.log-in {
border: black solid 1px;
border-radius: 25px;
padding: 10px;
background-color: #57573f;
margin-bottom: 0px;
}
.loading-image img {
width: 100px;
height: 100px;
animation: spinY 1s linear infinite;
margin: 20px auto;
margin-top: 100px;
z-index: 9999;
}
@keyframes spinY {
0% { transform: rotateY(0deg); }
100% { transform: rotateY(360deg); }
}
</style>
<script>
setTimeout(function() {
window.location.href = "homepage.php";
}, 3000);
</script>';
exit();
} else {
$login_error = "Invalid login credentials.";
}
} else {
$login_error = "Please fill in all fields.";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
<link rel="stylesheet" href="styles.css">
<link rel="shortcut icon" href="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" type="image/x-icon">
<link href="https://fonts.googleapis.com/css2?family=Beau+Rivage&display=swap" rel="stylesheet">
</head>
<body>
<header>
<div>
<a class="logo-div" href="index.php" target="_self" onclick="showLoadingScreen('Loading...')">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="Logo">
<h1>Happy Ending</h1>
</a>
</div>
<nav>
<ul>
<li><a onclick="showLoadingScreen('Loading...');" href="" target="_self">OUR PRODUCT</a></li>
<li><a onclick="showLoadingScreen('Loading...')" href="" target="_self" href="#">HELP & SUPPORT</a></li>
<li><a onclick="showLoadingScreen('Loading...')" href="" target="_self" href="#">GUEST</a></li>
</ul>
</nav>
</header>
<main>
<img class="login-logo" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726841328/rahjpg3k7mdtnow4ttux.png" alt="LogIn Logo">
<section class="login-form">
<h2>LOG IN</h2>
<hr>
<!-- Display login error if exists -->
<?php if (isset($login_error)): ?>
<p class="error"><?= $login_error ?></p>
<?php endif; ?>
<form action="index.php" method="post">
<label for="login">Username, Email, or Phone:</label>
<input type="text" id="login" name="login" placeholder="Username, Email, or Phone" required><br/>
<label for="password">Password:</label>
<div class="password-container">
<input type="password" id="password" name="password" placeholder="Password" pattern="^(?=.*[0-9].*[0-9])[a-zA-Z0-9]{8,}$"
title="Password must be at least 8 characters long and contain at least 2 numbers.">
<img src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726940114/pnpa3clu4ece0xadanxb.png" id="togglePassword" class="toggle-password" alt="Toggle Password">
</div>
<div class="forgot-create">
<a href="forget.php" target="_self" onclick="showLoadingScreen('Loading Password Reset');">Forgot Password?</a>
<input type="submit" value="SIGN IN">
<a onclick="showLoadingScreen('Loading...')" href="create-acc.php" target="_self">Create Account</a>
</div>
</form>
</section>
</main>
<footer>
<p class="copyright">© 2024 Happy Ending. All rights reserved.</p>
<nav>
<ul>
<li class="about-us"><a href="#">ABOUT US</a></li>
<li><a href="https://www.facebook.com" target="_blank"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1724068194/angoienw2wu8c1aqdrge.png" alt="FB-logo"></a></li>
<li><a href="https://www.instagram.com" target="_blank"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726891138/zzzgspgokfq1sbc9sjmu.webp" alt="IG-logo"></a></li>
<li><a href="https://www.x.com" target="_blank"><img class="icons-picture" src="https://res.cloudinary.com/drkmgpcad/image/upload/v1726890890/edvvrnyg1wewlm1onmzs.png" alt="X-logo"></a></li>
</ul>
</nav>
</footer>
<script src="script.js"></script>
</body>
</html>