What are some best practices for securely storing and retrieving user passwords in PHP?

Storing and retrieving user passwords securely is crucial to protect user data from unauthorized access. One best practice is to hash passwords using a strong hashing algorithm like bcrypt before storing them in the database. When retrieving passwords, always compare the hashed input password with the stored hashed password to verify the user's identity.

// Storing user password securely
$hashed_password = password_hash($password, PASSWORD_BCRYPT);

// Retrieving user password securely
if (password_verify($input_password, $stored_hashed_password)) {
    // Passwords match, user is authenticated
} else {
    // Passwords do not match, authentication failed
}