Answer the question
In order to leave comments, you need to log in
Is it safe to store authentication data in clear text for MySQL database?
How safe is it to store MySQL database authentication data in a .php file?!
I am a very green person in this business and very paranoid. Can you please tell me how safe these methods are? Maybe there are other ways? Maybe you should not store passwords directly in such an open form? Can it be better to come up with some self-encryption mechanisms?
<?php #Вариант 1
$host = 'localhost';
$name_bd = 'myBase';
$user = 'admin';
$password = '1234567';
?>
<?php #Вариант 2
define('HOST', 'localhost');
define('NAME_BD', 'myBase');
define('USER', 'admin');
define('PASSWORD', '1234567');
?>
Answer the question
In order to leave comments, you need to log in
Passwords and other sensitive data can be passed through environment variables. Only the application itself has access to environment variables through the web server (with the rights of the user under which it is launched). For example like this (Linux).
This is standard practice. But you need to keep in mind three points:
- the password file must be outside the web server
- the file must contain a user who has rights only to the site database and only the minimum necessary rights
- MySQL should only accept connections from 127.0.0.1
This is normal practice. If someone gets access to the files on your server, then it will not matter to you whether he finds the login / password to the database in this file or stupidly resets the MySQL root password. Therefore, set aside paranoia! You are doing everything right.
Between the options, I would choose the 1st, but I don’t see much difference.
Ps Usually, the access file is kept in a folder inaccessible to the web server. See how it is implemented using the Yii framework example ( https://github.com/yiisoft/yii2-app-basic). The web server only looks in the web folder. Everything else, including the config folder, is not visible to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question