leonvsc / Premaz

1 stars 0 forks source link

Verberg het wachtwoord van de database #43

Closed NielsWarnaar closed 2 years ago

NielsWarnaar commented 2 years ago

Het wachtwoord is nu te vinden in de bestanden, aangezien de repo op public staat door de workflow en er bots aan het zoeken zijn naar wachtwoorden kunnen we deze beter verbergen voordat de database kapotgaat.

leonvsc commented 2 years ago
$root = realpath($_SERVER["DOCUMENT_ROOT"]);

            $filePath = $root . "/DAL/creds.dat"; # This uses a json file called creds.dat stored 1 folder above the site's root. This makes it inaccessible from the web. It stores the database credentials
            $file = fopen($filePath, "r") or die ("<br/> Unable to open credentials");
            $fileText = fread($file, filesize($filePath));
            fclose($file);
            $json = json_decode($fileText, true);
            $this->conn = mysqli_connect($json["DB_HOST"], $json["DB_USER"], $json["DB_PASS"], $json["DB_DB"]) or die ("<br/> Could not connect to the SQL server");
leonvsc commented 2 years ago

In plaats van bovenstaand te gebruiken kunnen we een dotenv file gebruiken. Dit maakt het een stuk makkelijker.

https://github.com/vlucas/phpdotenv

Deze kan geinstalleerd worden via composer.

NielsWarnaar commented 2 years ago

Prima, zolang het wachtwoord niet zichtbaar is, is het goed. Kijk maar wat het makkelijkst is😉