How can the PHP functions password_hash() and password_verify() be used securely for password management?
To securely manage passwords in PHP, you can use the `password_hash()` function to securely hash passwords before storing them in the database, and the `password_verify()` function to verify a user's input password against the stored hashed password. This helps protect user passwords from being exposed in case of a data breach.
// Hashing the password before storing it in the database
$password = "secret_password";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Storing $hashed_password in the database
// Verifying the user's input password during login
$user_input_password = "user_input_password";
if (password_verify($user_input_password, $hashed_password)) {
// Password is correct
// Proceed with login
} else {
// Password is incorrect
// Display error message
}