What are the best practices for handling password encryption and comparison in PHP scripts?

When handling password encryption and comparison in PHP scripts, it is important to securely hash passwords using a strong hashing algorithm like bcrypt. Additionally, always use a unique salt for each password to prevent rainbow table attacks. When comparing passwords, use the password_verify function to securely compare the hashed password with the user input.

// Hashing a password
$password = 'password123';
$hashedPassword = password_hash($password, PASSWORD_BCRYPT);

// Comparing a password
$userInput = 'password123';
if (password_verify($userInput, $hashedPassword)) {
    echo 'Password is correct!';
} else {
    echo 'Password is incorrect!';
}