-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
93 lines (74 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
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
<?php
/*
Simple login system in PHP to demonstrate Sesher usage
AGPLv3
@aaviator42
*/
require 'Sesher.php';
session_start();
//BCRYPT password hash generated with password_hash()
//default: password1234
$hashedPassword = '$2y$10$sV9cOUot6w3y3eivMrTmq.O/NteebWDY5tY7rx9wSJoEMXZTxjO8u';
//logout if request made to ?logout=true
if(isset($_GET["logout"]) && $_GET["logout"]){
\Sesher\stop();
header('Location: '. $_SERVER['SCRIPT_NAME']);
}
//if form submitted, check if password correct
if(!\Sesher\check()){
if(isset($_POST["password"])){
if(password_verify($_POST['password'], $hashedPassword)){
//password is correct!
\Sesher\start();
} else {
//password is incorrect
echo "Incorrect password! <hr>";
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Simple Login Page</title>
<style>
body {
font-family: monospace;
max-width: 50rem;
padding: 2rem;
margin: auto;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="robots" content="noindex, nofollow, noarchive">
</head>
<body>
<h2>Simple Login Page</h2>
<?php
if(\Sesher\check()){
//user logged in
print 'You are logged in!<br>';
} else{
//user logged out
loginFormPrint();
}
footerPrint();
function loginFormPrint(){
print ' <h3>Login</h3>
<form action="#" method="post">
Password: <input type="password" name="password" required><br>
<input type="submit" value="Login!" />
</form>
';
}
function footerPrint(){
print '<br><br><hr><small>';
if(\Sesher\check()){
print '<a href="?logout=true">Logout</a> | ' ;
}
print '<a href="https://github.com/aaviator42/simple-login">Help/Source</a></small>';
}
?>
</body>
</html>