diff --git a/php/src/Auth/AuthManager.php b/php/src/Auth/AuthManager.php index a4bc96b6..f3775146 100644 --- a/php/src/Auth/AuthManager.php +++ b/php/src/Auth/AuthManager.php @@ -4,25 +4,25 @@ namespace AIO\Auth; use AIO\Data\ConfigurationManager; use AIO\Data\DataConst; -use \DateTime; +use DateTime; class AuthManager { private const string SESSION_KEY = 'aio_authenticated'; - private ConfigurationManager $configurationManager; - public function __construct(ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; + public function __construct( + private readonly ConfigurationManager $configurationManager + ) { } - public function CheckCredentials(string $password) : bool { + public function CheckCredentials(string $password): bool { return hash_equals($this->configurationManager->GetPassword(), $password); } - public function CheckToken(string $token) : bool { + public function CheckToken(string $token): bool { return hash_equals($this->configurationManager->GetToken(), $token); } - public function SetAuthState(bool $isLoggedIn) : void { + public function SetAuthState(bool $isLoggedIn): void { if (!$this->IsAuthenticated() && $isLoggedIn === true) { $date = new DateTime(); @@ -40,7 +40,7 @@ class AuthManager { $_SESSION[self::SESSION_KEY] = $isLoggedIn; } - public function IsAuthenticated() : bool { + public function IsAuthenticated(): bool { return isset($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY] === true; } } diff --git a/php/src/Auth/PasswordGenerator.php b/php/src/Auth/PasswordGenerator.php index 6e9ee9a1..4c3e2819 100644 --- a/php/src/Auth/PasswordGenerator.php +++ b/php/src/Auth/PasswordGenerator.php @@ -2,11 +2,11 @@ namespace AIO\Auth; -use AIO\Data\ConfigurationManager; +use Random\RandomException; -class PasswordGenerator -{ - private array $words = [ +class PasswordGenerator { + + private const array WORDS = [ 'abacus', 'abdomen', 'abdominal', @@ -7785,14 +7785,18 @@ class PasswordGenerator 'zoom', ]; - public function GeneratePassword(int $length) : string { + + /** + * @throws RandomException + */ + public function GeneratePassword(int $length): string { $password = ''; - for($i = 0; $i < $length; $i ++) { - if($password !== '') { + for ($i = 0; $i < $length; $i++) { + if ($password !== '') { $password = $password . ' '; } - $password = $password . $this->words[random_int(0, 7775)]; + $password = $password . PasswordGenerator::WORDS[random_int(0, 7775)]; } return $password;