What are the potential security risks of storing passwords as plaintext in a PHP application?
Storing passwords as plaintext in a PHP application is a significant security risk because if the database is compromised, all user passwords can be easily accessed. To mitigate this risk, passwords should be hashed before storing them in the database. Hashing is a one-way cryptographic function that converts the password into a fixed-length string of characters that cannot be reversed to obtain the original password.
// Hash the password before storing it in the database
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Store $hashed_password in the database