-
Notifications
You must be signed in to change notification settings - Fork 715
/
Copy pathAuthManager.php
46 lines (34 loc) · 1.4 KB
/
AuthManager.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
<?php
namespace AIO\Auth;
use AIO\Data\ConfigurationManager;
use AIO\Data\DataConst;
use \DateTime;
readonly class AuthManager {
private const string SESSION_KEY = 'aio_authenticated';
public function __construct(
private ConfigurationManager $configurationManager
) {
}
public function CheckCredentials(string $password) : bool {
return hash_equals($this->configurationManager->GetPassword(), $password);
}
public function CheckToken(string $token) : bool {
return hash_equals($this->configurationManager->GetToken(), $token);
}
public function SetAuthState(bool $isLoggedIn) : void {
if (!$this->IsAuthenticated() && $isLoggedIn === true) {
$date = new DateTime();
$dateTime = $date->getTimestamp();
$_SESSION['date_time'] = $dateTime;
$df = disk_free_space(DataConst::GetSessionDirectory());
if ($df !== false && (int)$df < 10240) {
error_log(DataConst::GetSessionDirectory() . " has only less than 10KB free space. The login might not succeed because of that!");
}
file_put_contents(DataConst::GetSessionDateFile(), (string)$dateTime);
}
$_SESSION[self::SESSION_KEY] = $isLoggedIn;
}
public function IsAuthenticated() : bool {
return isset($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY] === true;
}
}