Make password an attribute

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zmdl 2026-01-19 14:55:29 +01:00
parent b2f992d955
commit 4d8e959608
3 changed files with 9 additions and 14 deletions

View file

@ -15,7 +15,7 @@ readonly class AuthManager {
} }
public function CheckCredentials(string $password) : bool { public function CheckCredentials(string $password) : bool {
return hash_equals($this->configurationManager->GetPassword(), $password); return hash_equals($this->configurationManager->password, $password);
} }
public function CheckToken(string $token) : bool { public function CheckToken(string $token) : bool {

View file

@ -18,6 +18,11 @@ class ConfigurationManager
set { $this->set('AIO_TOKEN', $value); } set { $this->set('AIO_TOKEN', $value); }
} }
public string $password {
get => $this->get('password', '');
set { $this->set('password', $value); }
}
public function GetConfig() : array public function GetConfig() : array
{ {
if ($this->config === [] && file_exists(DataConst::GetConfigFile())) if ($this->config === [] && file_exists(DataConst::GetConfigFile()))
@ -29,16 +34,6 @@ class ConfigurationManager
return $this->config; return $this->config;
} }
public function GetPassword() : string {
return $this->GetConfig()['password'];
}
public function SetPassword(string $password) : void {
$config = $this->GetConfig();
$config['password'] = $password;
$this->WriteConfig($config);
}
private function get(string $key, mixed $fallbackValue = null) : mixed { private function get(string $key, mixed $fallbackValue = null) : mixed {
return $this->GetConfig()[$key] ?? $fallbackValue; return $this->GetConfig()[$key] ?? $fallbackValue;
} }
@ -586,7 +581,7 @@ class ConfigurationManager
throw new InvalidSettingConfigurationException("Please enter your current password."); throw new InvalidSettingConfigurationException("Please enter your current password.");
} }
if ($currentPassword !== $this->GetPassword()) { if ($currentPassword !== $this->password) {
throw new InvalidSettingConfigurationException("The entered current password is not correct."); throw new InvalidSettingConfigurationException("The entered current password is not correct.");
} }
@ -603,7 +598,7 @@ class ConfigurationManager
} }
// All checks pass so set the password // All checks pass so set the password
$this->SetPassword($newPassword); $this->set('password', $newPassword);
} }
public function GetApachePort() : string { public function GetApachePort() : string {

View file

@ -17,7 +17,7 @@ readonly class Setup {
} }
$password = $this->passwordGenerator->GeneratePassword(8); $password = $this->passwordGenerator->GeneratePassword(8);
$this->configurationManager->SetPassword($password); $this->configurationManager->password = $password;
return $password; return $password;
} }