What is the difference between encrypting and hashing passwords in PHP?

When storing passwords in a database, it is important to protect them from being easily compromised. Encrypting passwords involves using a reversible algorithm to convert the password into a scrambled format that can be decrypted back to its original form. Hashing passwords, on the other hand, involves using a one-way algorithm to convert the password into a fixed-length string that cannot be reversed.

// Encrypting a password
$plaintext_password = 'password123';
$encrypted_password = password_hash($plaintext_password, PASSWORD_DEFAULT);

// Storing the encrypted password in the database

// Verifying the password
$entered_password = 'password123';
if (password_verify($entered_password, $encrypted_password)) {
    echo 'Password is correct';
} else {
    echo 'Password is incorrect';
}