Skip to content
PHP Logo

What are the potential security risks of storing passwords in plaintext in PHP config files?

Storing passwords in plaintext in PHP config files poses a significant security risk as anyone with access to the file can easily view the sensitive information. To mitigate this risk, passwords should be stored in a hashed format using a secure hashing algorithm like bcrypt. This way, even if the config file is compromised, the actual passwords remain protected.

php
// Hashing the password before storing it in the config file
$password = password_hash('your_password_here', PASSWORD_DEFAULT);

// Storing the hashed password in the config file
define('DB_PASSWORD', $password);