-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.php
58 lines (48 loc) · 1.61 KB
/
admin.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
<?php
session_start();
$servername = "localhost";
$dbname = "id22209619_gfoss_lab";
$username = "id22209619_root";
$password = "Root123@";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$username = test_input($_POST["username"]);
$password = test_input($_POST["password"]);
$passwordHash = hash('sha256', $password);
$sql = "SELECT * FROM Users WHERE Username='$username' AND PasswordHash='$passwordHash' AND IsApproved=1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Login successful
$_SESSION["username"] = $username;
header("Location: index.php");
exit();
} else {
$error_message = "Invalid username or password, or account not approved.";
}
$conn->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Admin Login</title>
<link rel="stylesheet" type="text/css" href="gsoc2024-DIY-IoT-Physics/css/style.css">
</head>
<body>
<div class="container">
<h2>Login</h2>
<?php if (isset($error_message)): ?>
<div class='error'><?php echo $error_message; ?></div>
<?php endif; ?>
<form method="post" action="login.php">
<input type="text" name="username" placeholder="Username" required>
<input type="password" name="password" placeholder="Password" required>
<input type="submit" value="Login">
</form>
<a href="signup.php">Don't have an account? Sign up</a>
</div>
</body>
</html>