-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAuth.php
More file actions
83 lines (57 loc) · 1.41 KB
/
Copy pathAuth.php
File metadata and controls
83 lines (57 loc) · 1.41 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
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
<?php
namespace Dreamcoil;
class Auth
{
/**
* Creates an authentication session.
* Uses auth_expire on the config to get the session lifetime.
*
* @param null $data
*/
public function set($data = null)
{
$config = new Config();
$hash = hash('ripemd160', microtime(true));
if($config->get('auth_expire') !== null)
$lifetime = $config->get('auth_expire');
else
$lifetime = ONE_DAY;
session_set_cookie_params($lifetime,"/");
if(session_id() == "") session_start();
$lifetime += time();
if(!isset($_COOKIE['auth-key'])) setcookie('auth-key', $hash, $lifetime);
if($data !== null) $_SESSION = $data;
}
/**
* Checks if the user is authenitcated
*
* @return bool
*/
public function check()
{
if(isset($_COOKIE['auth-key']))
return true;
else
return false;
}
/**
* Destroys a current function
*
* @return bool
*/
public function destroy()
{
setcookie('auth-key' , null, time() - ONE_DAY);
$_COOKIE['auth-key'] = null;
if(session_id() != "") session_destroy();
if($_COOKIE['auth-key'] === null) return true;
return false;
}
/**
* Starting a sessopn
*/
public function start()
{
session_start();
}
}