From daac17ea3cbffb41370b5ba52e307340ab9772a6 Mon Sep 17 00:00:00 2001 From: lewmilburn Date: Mon, 30 Oct 2023 18:16:08 +0000 Subject: [PATCH] Added more vault settings --- .gitignore | 2 +- Web/data/fileManager.php | 16 ++++++++-------- Web/settings.php | 4 +++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 57d5335..13ff460 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /.idea/ users.json -default.vault \ No newline at end of file +admin.vault \ No newline at end of file diff --git a/Web/data/fileManager.php b/Web/data/fileManager.php index 6bf3968..d4978e0 100644 --- a/Web/data/fileManager.php +++ b/Web/data/fileManager.php @@ -7,18 +7,18 @@ class fileManager { private string $usersFile; - private string $vaultFile; + private string $defaultVault; public function __construct() { - $this->usersFile = __DIR__ . '/../' . USERS_FILE; - $this->vaultFile = __DIR__ . '/../' . VAULT_FILE; + $this->usersFile = __DIR__ . '/../' . SECURE_LOCATION . USERS_FILE; + $this->defaultVault = __DIR__ . '/../' . SECURE_LOCATION . DEFAULT_USER . '.vault'; if (!file_exists($this->usersFile)) { $this->initialiseUsers(); } - if (!file_exists($this->vaultFile)) { + if (!file_exists($this->defaultVault)) { $this->initialiseVault(); } } @@ -32,18 +32,18 @@ public function getUserData(string $username) private function initialiseUsers(): void { $UserFile = fopen($this->usersFile, "w"); - fwrite($UserFile, '{"users" : []}'); + fwrite($UserFile, '[{"user":"admin","passkey":"'.password_hash(TEMPORARY_PASSWORD,PASSWORD_DEFAULT).'"}]'); fclose($UserFile); } private function initialiseVault(): void { - $VaultFile = fopen($this->vaultFile, "w"); + $VaultFile = fopen($this->defaultVault, "w"); $em = new encryptionManager(); - $EncryptedData = $em->encrypt('"users" : []',$em->generateKey(TEMPORARY_PASSWORD)); + $EncryptedData = $em->encrypt('[{}]',$em->generateKey(PASSWORD_DEFAULT)); - fwrite($VaultFile, $EncryptedData[0].'[!]'.$EncryptedData[1]); + fwrite($VaultFile, $EncryptedData[0].FILE_SEPARATOR.$EncryptedData[1]); fclose($VaultFile); } } diff --git a/Web/settings.php b/Web/settings.php index 6c8800c..73c7cfe 100644 --- a/Web/settings.php +++ b/Web/settings.php @@ -10,7 +10,9 @@ // Filesystem storage settings const USERS_FILE = 'users.json'; -const VAULT_FILE = 'default.vault'; +const DEFAULT_USER = 'admin'; +const SECURE_LOCATION = ''; // relative to this file. +const FILE_SEPARATOR = '[SEP]'; // Database storage settings const DB_HOST = '';