What are the best practices for storing passwords in a MySQL database using PHP?

When storing passwords in a MySQL database using PHP, it is crucial to securely hash the passwords before storing them to protect user data in case of a breach. The recommended approach is to use the PHP password_hash() function to generate a secure hash of the password and store it in the database. When verifying a user's password during login, use the password_verify() function to compare the hashed password with the input password.

// Hash and store password
$password = 'user_password';
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Store $hashed_password in the database

// Verify password during login
$input_password = 'user_input_password';
$stored_hashed_password = 'retrieved_hashed_password_from_database';

if (password_verify($input_password, $stored_hashed_password)) {
    // Passwords match, proceed with login
} else {
    // Passwords do not match, handle error
}