What are some potential security risks associated with hardcoding passwords in PHP scripts?
Hardcoding passwords in PHP scripts poses a significant security risk as the passwords are exposed in plain text within the code. If an attacker gains access to the codebase, they can easily retrieve the passwords and compromise sensitive data. To mitigate this risk, it is recommended to store passwords securely using techniques such as hashing and salting.
// Store passwords securely using hashing and salting
$password = "mypassword123";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Verify password
if (password_verify($password, $hashed_password)) {
echo "Password is correct";
} else {
echo "Password is incorrect";
}