What are the best practices for securely storing and comparing encrypted passwords in PHP?

When storing passwords in a database, it is crucial to encrypt them using a secure hashing algorithm like bcrypt. To compare encrypted passwords, you should use the password_verify() function provided by PHP, which securely compares a plaintext password with its hashed version. Additionally, always use prepared statements when interacting with the database to prevent SQL injection attacks.

// Storing encrypted password
$password = "secret_password";
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Comparing encrypted password
$entered_password = "user_input_password";
if (password_verify($entered_password, $hashed_password)) {
    echo "Password is correct!";
} else {
    echo "Password is incorrect!";
}