-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
101 lines (78 loc) · 2.93 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
session_start();
// Include the configuration file
require_once 'config.php';
if (isset($_SESSION['username'])) {
header("Location: home.php");
exit();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
// Establish a database connection
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// For simplicity, let's assume you have a table named 'users' with columns 'username' and 'password'
$query = "SELECT * FROM users WHERE username = '$username'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$hashedPassword = $row['password'];
// Use password_verify to check if the provided password matches the stored hash
if (password_verify($password, $hashedPassword)) {
$_SESSION['username'] = $username;
header("Location: home.php");
exit();
} else {
$error_message = "Invalid username or password";
}
} else {
$error_message = "Invalid username or password";
}
$conn->close();
}
?>
<!DOCTYPE HTML>
<!--
Eventually by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<title>Coffee Chat Beta</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body >
<!-- Header -->
<h2>Login</h2>
<?php if(isset($error_message)) { echo "<p>$error_message</p>"; } ?>
<form method="post" action="">
<label for="username">Username:</label>
<input type="text" name="username" required><br>
<label for="password">Password:</label>
<input type="password" name="password" required><br>
<input type="submit" value="Login">
</form>
<p>Don't have an account? <a href="signup.php">Sign up here</a>.</p>
<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a href="#" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon brands fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon brands fa-github"><span class="label">GitHub</span></a></li>
<li><a href="https://www5.cbox.ws/box/?boxid=947502&boxtag=uvqEHi" class="icon fa-envelope"><span class="label">Live Chat</span></a></li>
</ul>
<ul class="copyright">
<li>© Coffee Chat Beta 2023</li><li>Built by Dila</a></li>
<li>
</ul>
</footer>
<!-- Scripts -->
<script src="assets/js/main.js"></script>
</body>
</html>