Can you explain the difference between encryption and hashing in the context of PHP password security?

Encryption is a reversible process where data is encoded in such a way that it can be decrypted back to its original form. Hashing, on the other hand, is a one-way process where data is converted into a fixed-length string of characters, making it impossible to reverse the process and retrieve the original data. In the context of PHP password security, it is recommended to use hashing to store passwords securely, as it provides a way to verify passwords without storing the actual password in the database.

// Hashing a password using PHP's password_hash function
$password = "secretPassword";
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Verifying a password using PHP's password_verify function
$enteredPassword = "secretPassword";
if (password_verify($enteredPassword, $hashedPassword)) {
    echo "Password is correct!";
} else {
    echo "Password is incorrect!";
}