What is the difference between hashing and encryption in PHP, and how does it relate to generating secure tokens?

Hashing is a one-way process that converts input data into a fixed-size string of characters, while encryption is a two-way process that converts data into a format that can be reversed back to its original form. When generating secure tokens in PHP, it is recommended to use hashing functions like password_hash() to securely store and compare tokens without the need for decryption.

$token = bin2hex(random_bytes(16)); // Generate a random token
$hashed_token = password_hash($token, PASSWORD_DEFAULT); // Hash the token for secure storage