What are common pitfalls when using if statements in PHP for password validation?

One common pitfall when using if statements for password validation in PHP is not properly hashing the password before comparing it. To solve this issue, always hash the password using a secure hashing algorithm like password_hash() before storing it in the database and then use password_verify() to compare the hashed password with the user input.

// Example of password validation using password_hash() and password_verify()

// Hash the password before storing it in the database
$hashed_password = password_hash($user_input_password, PASSWORD_DEFAULT);

// Compare the hashed password with the user input
if (password_verify($user_input_password, $hashed_password)) {
    // Password is correct
    echo "Password is correct";
} else {
    // Password is incorrect
    echo "Password is incorrect";
}