From 4141eaf3ea3ee50ef288e8e4307c20238334a1c7 Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Sat, 9 Nov 2019 23:56:28 +0100 Subject: [PATCH] added a better way to store credentials --- .gitignore | 2 +- assets/php/example_config.json | 7 +++++++ assets/php/utils.php | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 assets/php/example_config.json diff --git a/.gitignore b/.gitignore index 848ff49..d399df6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -./assets/php/config.json \ No newline at end of file +assets/php/config.json \ No newline at end of file diff --git a/assets/php/example_config.json b/assets/php/example_config.json new file mode 100644 index 0000000..a2d5aa8 --- /dev/null +++ b/assets/php/example_config.json @@ -0,0 +1,7 @@ +{ + "host":"localhost", + "dbname": "db", + "user": "user", + "password": "pass", + "kind": "mysql" +} \ No newline at end of file diff --git a/assets/php/utils.php b/assets/php/utils.php index 3f7462c..0fa1cb0 100644 --- a/assets/php/utils.php +++ b/assets/php/utils.php @@ -3,11 +3,11 @@ $SESSION_COOKIE_NAME = "connection_id"; $MAX_COOKIE_LIFE = time() + 86400 * 30; // 30 days max +$config_array = json_decode(file_get_contents("config.json", true)); -$dsn = "mysql:dbname=food-inventory;host=localhost"; -$user = 'food-inventory'; -$password = 'xt3apB8uVbFIYJvp'; -$PDO = new PDO($dsn, $user, $password); +$dsn = $config_array->{"kind"} . ":dbname=" + . $config_array->{"dbname"} . ";host=" . $config_array->{"host"}; +$PDO = new PDO($dsn, $config_array->{"user"}, $config_array->{"password"}); $PDO->query('SET CHARSET UTF8'); function is_https()