From 8f75dfc09fa18bd8b316fbc55f74832e308e845e Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 30 Oct 2023 18:21:34 +0000 Subject: [PATCH] Apply fixes from StyleCI --- Web/authentication/authenticationManager.php | 4 ++-- Web/data/const.php | 2 +- Web/data/fileManager.php | 13 +++++++------ Web/encryption/encryptionManager.php | 14 ++++++++------ Web/event/routeHandler.php | 10 +++++----- Web/loader.php | 6 ++---- Web/settings.php | 2 +- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Web/authentication/authenticationManager.php b/Web/authentication/authenticationManager.php index 4327658..2449fa7 100644 --- a/Web/authentication/authenticationManager.php +++ b/Web/authentication/authenticationManager.php @@ -24,7 +24,7 @@ public function Login(string $username, string $password) } } else { $eh = new errorHandler(); - $eh->sessionRequired('authentication','authenticationManager','Login'); + $eh->sessionRequired('authentication', 'authenticationManager', 'Login'); exit; } } @@ -38,7 +38,7 @@ public function Logout() return true; } else { $eh = new errorHandler(); - $eh->sessionRequired('authentication','authenticationManager','Logout'); + $eh->sessionRequired('authentication', 'authenticationManager', 'Logout'); exit; } } diff --git a/Web/data/const.php b/Web/data/const.php index 1b4e068..bcb886d 100644 --- a/Web/data/const.php +++ b/Web/data/const.php @@ -3,4 +3,4 @@ const DEV = 0; const PROD = 1; const DATABASE = 0; -const FILESYSTEM = 1; \ No newline at end of file +const FILESYSTEM = 1; diff --git a/Web/data/fileManager.php b/Web/data/fileManager.php index d4978e0..4853782 100644 --- a/Web/data/fileManager.php +++ b/Web/data/fileManager.php @@ -11,8 +11,8 @@ class fileManager public function __construct() { - $this->usersFile = __DIR__ . '/../' . SECURE_LOCATION . USERS_FILE; - $this->defaultVault = __DIR__ . '/../' . SECURE_LOCATION . DEFAULT_USER . '.vault'; + $this->usersFile = __DIR__.'/../'.SECURE_LOCATION.USERS_FILE; + $this->defaultVault = __DIR__.'/../'.SECURE_LOCATION.DEFAULT_USER.'.vault'; if (!file_exists($this->usersFile)) { $this->initialiseUsers(); @@ -26,22 +26,23 @@ public function __construct() public function getUserData(string $username) { $usersFile = file_get_contents($this->usersFile); + return json_decode($usersFile); } private function initialiseUsers(): void { - $UserFile = fopen($this->usersFile, "w"); - fwrite($UserFile, '[{"user":"admin","passkey":"'.password_hash(TEMPORARY_PASSWORD,PASSWORD_DEFAULT).'"}]'); + $UserFile = fopen($this->usersFile, 'w'); + fwrite($UserFile, '[{"user":"admin","passkey":"'.password_hash(TEMPORARY_PASSWORD, PASSWORD_DEFAULT).'"}]'); fclose($UserFile); } private function initialiseVault(): void { - $VaultFile = fopen($this->defaultVault, "w"); + $VaultFile = fopen($this->defaultVault, 'w'); $em = new encryptionManager(); - $EncryptedData = $em->encrypt('[{}]',$em->generateKey(PASSWORD_DEFAULT)); + $EncryptedData = $em->encrypt('[{}]', $em->generateKey(PASSWORD_DEFAULT)); fwrite($VaultFile, $EncryptedData[0].FILE_SEPARATOR.$EncryptedData[1]); fclose($VaultFile); diff --git a/Web/encryption/encryptionManager.php b/Web/encryption/encryptionManager.php index d1c0af1..2a51c36 100644 --- a/Web/encryption/encryptionManager.php +++ b/Web/encryption/encryptionManager.php @@ -10,13 +10,14 @@ class encryptionManager public function generateKey($password): string { try { - return sodium_crypto_pwhash(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, $password, '0000000000000000',SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13); + return sodium_crypto_pwhash(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, $password, '0000000000000000', SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13); } catch (SodiumException $e) { $eh = new errorHandler(); - $eh->error('encryption', 'encryptionManager','encrypt',$e,'500'); + $eh->error('encryption', 'encryptionManager', 'encrypt', $e, '500'); exit; } } + public function encrypt($string, $key): array { try { @@ -27,13 +28,14 @@ public function encrypt($string, $key): array sodium_memzero($string); sodium_memzero($key); - return array($encryptedData,$nonce); + return [$encryptedData, $nonce]; } catch (SodiumException|\Exception $e) { $eh = new errorHandler(); - $eh->error('encryption', 'encryptionManager','encrypt',$e,'500'); + $eh->error('encryption', 'encryptionManager', 'encrypt', $e, '500'); exit; } } + public function decrypt($string, $key, $nonce): string|null { try { @@ -47,8 +49,8 @@ public function decrypt($string, $key, $nonce): string|null return $decryptedData; } catch (SodiumException|\Exception $e) { $eh = new errorHandler(); - $eh->error('encryption', 'encryptionManager','decrypt',$e,'500'); + $eh->error('encryption', 'encryptionManager', 'decrypt', $e, '500'); exit; } } -} \ No newline at end of file +} diff --git a/Web/event/routeHandler.php b/Web/event/routeHandler.php index e4ea937..164a6c7 100644 --- a/Web/event/routeHandler.php +++ b/Web/event/routeHandler.php @@ -14,17 +14,17 @@ public function getRequest($url, $file): void public function endRouter(): void { $eh = new errorHandler(); - $eh->fileNotFound('event','routeHandler','endRouter'); + $eh->fileNotFound('event', 'routeHandler', 'endRouter'); } private function displayFile($file): void { - if (file_exists(__DIR__ . '/../' .$file)) { - require_once __DIR__ . '/../' .$file; + if (file_exists(__DIR__.'/../'.$file)) { + require_once __DIR__.'/../'.$file; } else { $eh = new errorHandler(); - $eh->fileNotFound('event','routeHandler','displayFile'); + $eh->fileNotFound('event', 'routeHandler', 'displayFile'); } exit; } -} \ No newline at end of file +} diff --git a/Web/loader.php b/Web/loader.php index db5ae5d..510f1f2 100644 --- a/Web/loader.php +++ b/Web/loader.php @@ -1,6 +1,5 @@ error(null, null, null, 'Sodium not installed.', '500'); -} \ No newline at end of file +} diff --git a/Web/settings.php b/Web/settings.php index 73c7cfe..b2eb5a2 100644 --- a/Web/settings.php +++ b/Web/settings.php @@ -20,4 +20,4 @@ const DB_USER = ''; const DB_PASS = ''; const DB_PORT = ''; -const DB_PREFIX = 'va_'; \ No newline at end of file +const DB_PREFIX = 'va_';