What are the potential security risks of storing passwords in clear text in a database in PHP?
Storing passwords in clear text in a database in PHP poses a significant security risk as anyone with access to the database can easily view and misuse the passwords. To mitigate this risk, passwords should be securely hashed before storing them in the database. This way, even if the database is compromised, the actual passwords remain protected.
// Hashing the password before storing it in the database
$password = "password123";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Storing the hashed password in the database
$query = "INSERT INTO users (username, password) VALUES ('john_doe', '$hashed_password')";
// Execute the query
Keywords
Related Questions
- What are best practices for adding header information when sending emails in PHP?
- What are the potential pitfalls of using the PHP header() function for redirection?
- When using SQL queries in PHP to delete data from a database, what is the correct syntax for deleting multiple entries based on specific criteria?