What best practices should be followed when hashing passwords in PHP, and why is using md5 considered a security risk?

When hashing passwords in PHP, it is best practice to use a strong hashing algorithm like bcrypt or Argon2, along with a unique salt for each password. Using md5 for password hashing is considered a security risk because it is a fast hashing algorithm that is vulnerable to brute force attacks. It is recommended to avoid using md5 for password hashing and instead opt for more secure options.

// Hashing a password using bcrypt
$password = "securepassword123";
$options = [
    'cost' => 12,
];
$hashedPassword = password_hash($password, PASSWORD_BCRYPT, $options);

// Verifying a password
$enteredPassword = "securepassword123";
if (password_verify($enteredPassword, $hashedPassword)) {
    echo "Password is correct";
} else {
    echo "Password is incorrect";
}