What are the best practices for generating and storing activation codes in PHP?

When generating and storing activation codes in PHP, it is important to ensure that the codes are unique, secure, and not easily guessable. One best practice is to use a combination of random characters and numbers to create the activation code. Additionally, it is recommended to hash the activation code before storing it in the database to enhance security.

// Generate a random activation code
$activationCode = bin2hex(random_bytes(16));

// Hash the activation code before storing it in the database
$hashedActivationCode = password_hash($activationCode, PASSWORD_DEFAULT);