-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.php
31 lines (28 loc) · 1.09 KB
/
Token.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
<?php
// Class which is responsible for generating and chacking a JSON token
class Token
{
// Function responsible for generating a JSON token.
public static function generate()
{
// Return the JSON token.
return Session::put(Configuration::getConfiguration('session/token_name'), md5(uniqid()));
}
// Function responsible for checking a JSON token.
public static function check($token)
{
// Retrieves the token name which has been generated.
$tokenName = Configuration::getConfiguration('session/token_name');
// Checks if a sesson/token exists.
if(Session::exists($tokenName) && $token === Session::get($tokenName))
{
// If a token exists, then remove it to generate a new one.
Session::delete($tokenName);
// Return true if the above is applicable.
return true;
}
// Else return false.
return false;
}
}
?>