-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.php
More file actions
51 lines (46 loc) · 1.07 KB
/
auth.php
File metadata and controls
51 lines (46 loc) · 1.07 KB
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
<?php
require_once __DIR__ . '/log.php';
class Auth {
public static $password = '$2y$10$SLjwBwdOVvnMgWxvTI4Gb.YVcmDlPTpQystHMO2Kfyi/DS8rgA0Fm';
public static $username = 'guest';
public static function attempt($username, $password)
{
$userLogTime = new Log();
if($username == self::$username && password_verify($password, Auth::$password)){
//start the session
$_SESSION['logged_in_user'] = $username;
$userLogTime->info("User {$username} has logged in");
return true;
//redirect to authorized but not necessary
//header('location: ../public/authorized.php');
//exit();
}
else
{
$userLogTime->error("Incorrect login {$username}");
return false;
}
}
public static function check()
{
if(isset($_SESSION['logged_in_user'])){
return true;
} else {
return false;
}
}
public static function user()
{
if(isset($_SESSION['logged_in_user'])){
return self::$username;
}
}
public static function logout()
{
//clear $_SESSION username
session_unset();
//destroy session
session_destroy();
//start a new session?
}
}