What are the best practices for securely storing and handling passwords in PHP, such as encrypting them with MD5 or other hashing algorithms?

Storing passwords securely is crucial to protect user data from unauthorized access. Instead of using outdated hashing algorithms like MD5, it is recommended to use stronger algorithms like bcrypt or Argon2. These algorithms are specifically designed for password hashing and include features like salting and key stretching to increase security.

// Hashing a password using bcrypt
$password = "secret_password";
$hashed_password = password_hash($password, PASSWORD_BCRYPT);

// Verifying a password
$entered_password = "secret_password";
if (password_verify($entered_password, $hashed_password)) {
    echo "Password is correct!";
} else {
    echo "Password is incorrect!";
}