-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.php
More file actions
41 lines (33 loc) · 960 Bytes
/
Auth.php
File metadata and controls
41 lines (33 loc) · 960 Bytes
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
<?php
define('LOGGED_IN_USER', 'logged-in-user');
require_once 'Log.php';
class Auth
{
public static $password = '$2y$10$SLjwBwdOVvnMgWxvTI4Gb.YVcmDlPTpQystHMO2Kfyi/DS8rgA0Fm';
public static $username = 'guest';
public static function attempt($username, $password) {
$log = new Log();
if ($username == 'guest' && password_verify($password, self::$password)) {
session_start();
$_SESSION[LOGGED_IN_USER] = self::$username;
$log->info("User $username logged in.");
return true;
} else {
$log->error("User $username failed to log in!");
return false;
}
}
public static function check() {
return (isset($_SESSION[LOGGED_IN_USER]) && $_SESSION[LOGGED_IN_USER] == 'guest') ? true : false;
}
public static function user() {
return $_SESSION[LOGGED_IN_USER];
}
public static function logout() {
$log = new Log();
$log->info('User ' . self::user() . ' logged out.');
header('Location: login.php');
exit(0);
}
}
?>