What best practices should be followed when handling user authentication and error messages in PHP scripts?

When handling user authentication in PHP scripts, it is important to securely hash passwords using functions like password_hash() and password_verify(). Additionally, error messages should be handled carefully to avoid leaking sensitive information to users.

// User authentication example
$password = $_POST['password'];

// Hash the password
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Verify the password
if (password_verify($password, $hashed_password)) {
    echo 'Password is correct';
} else {
    echo 'Password is incorrect';
}