-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.php
61 lines (51 loc) · 1.79 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
<?php
require('./config.php');
session_start();
$error = "";
if (isset($_POST["username"]) && isset($_POST["password"])) {
$loggedInUser = null;
foreach ($config["users"] as $user) {
if ($user["username"] === $_POST["username"] && $user["password"] === $_POST["password"]) {
$loggedInUser = $user;
break;
}
}
if ($loggedInUser) {
$_SESSION["user"] = $loggedInUser;
header('location: editor.php');
die();
} else {
$error = "Incorrect username or password.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container vh-100 d-flex justify-content-center align-items-center">
<form method="post" action="index.php">
<?php if ($error !== "") { ?>
<div class="alert alert-danger" role="alert"><?php echo $error; ?></div>
<?php } ?>
<h1 class="h3 mb-3">Login</h1>
<p>Login with the user/passwords available in the <code>config.php</code> file</p>
<div class="form-group">
<label for="username" class="font-weight-bold">User</label>
<input type="text" class="form-control" id="username" name="username" value="johndoe">
</div>
<div class="form-group">
<label for="password" class="font-weight-bold">Password</label>
<input type="password" class="form-control" id="password" name="password" value="password">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Login">
</div>
</form>
</div>
</body>
</html>