mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-22 15:36:52 +00:00
Clean code and use const
Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
This commit is contained in:
parent
d674ba4f6e
commit
56aa613dfb
2 changed files with 20 additions and 16 deletions
|
|
@ -4,25 +4,25 @@ namespace AIO\Auth;
|
||||||
|
|
||||||
use AIO\Data\ConfigurationManager;
|
use AIO\Data\ConfigurationManager;
|
||||||
use AIO\Data\DataConst;
|
use AIO\Data\DataConst;
|
||||||
use \DateTime;
|
use DateTime;
|
||||||
|
|
||||||
class AuthManager {
|
class AuthManager {
|
||||||
private const string SESSION_KEY = 'aio_authenticated';
|
private const string SESSION_KEY = 'aio_authenticated';
|
||||||
private ConfigurationManager $configurationManager;
|
|
||||||
|
|
||||||
public function __construct(ConfigurationManager $configurationManager) {
|
public function __construct(
|
||||||
$this->configurationManager = $configurationManager;
|
private readonly ConfigurationManager $configurationManager
|
||||||
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CheckCredentials(string $password) : bool {
|
public function CheckCredentials(string $password): bool {
|
||||||
return hash_equals($this->configurationManager->GetPassword(), $password);
|
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);
|
return hash_equals($this->configurationManager->GetToken(), $token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetAuthState(bool $isLoggedIn) : void {
|
public function SetAuthState(bool $isLoggedIn): void {
|
||||||
|
|
||||||
if (!$this->IsAuthenticated() && $isLoggedIn === true) {
|
if (!$this->IsAuthenticated() && $isLoggedIn === true) {
|
||||||
$date = new DateTime();
|
$date = new DateTime();
|
||||||
|
|
@ -40,7 +40,7 @@ class AuthManager {
|
||||||
$_SESSION[self::SESSION_KEY] = $isLoggedIn;
|
$_SESSION[self::SESSION_KEY] = $isLoggedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function IsAuthenticated() : bool {
|
public function IsAuthenticated(): bool {
|
||||||
return isset($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY] === true;
|
return isset($_SESSION[self::SESSION_KEY]) && $_SESSION[self::SESSION_KEY] === true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace AIO\Auth;
|
namespace AIO\Auth;
|
||||||
|
|
||||||
use AIO\Data\ConfigurationManager;
|
use Random\RandomException;
|
||||||
|
|
||||||
class PasswordGenerator
|
class PasswordGenerator {
|
||||||
{
|
|
||||||
private array $words = [
|
private const array WORDS = [
|
||||||
'abacus',
|
'abacus',
|
||||||
'abdomen',
|
'abdomen',
|
||||||
'abdominal',
|
'abdominal',
|
||||||
|
|
@ -7785,14 +7785,18 @@ class PasswordGenerator
|
||||||
'zoom',
|
'zoom',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function GeneratePassword(int $length) : string {
|
|
||||||
|
/**
|
||||||
|
* @throws RandomException
|
||||||
|
*/
|
||||||
|
public function GeneratePassword(int $length): string {
|
||||||
$password = '';
|
$password = '';
|
||||||
|
|
||||||
for($i = 0; $i < $length; $i ++) {
|
for ($i = 0; $i < $length; $i++) {
|
||||||
if($password !== '') {
|
if ($password !== '') {
|
||||||
$password = $password . ' ';
|
$password = $password . ' ';
|
||||||
}
|
}
|
||||||
$password = $password . $this->words[random_int(0, 7775)];
|
$password = $password . PasswordGenerator::WORDS[random_int(0, 7775)];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $password;
|
return $password;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue