What are some alternative methods for resetting passwords in PHP applications without sending them via email?

When resetting passwords in PHP applications, sending them via email may not always be the most secure option due to potential vulnerabilities. One alternative method is to generate a unique token that can be used to reset the password. This token can be sent to the user via a secure channel such as SMS or displayed on a secure webpage.

// Generate a unique token for password reset
$token = bin2hex(random_bytes(16));

// Save the token in the database along with the user's ID and expiration time
// For example, you can store it in a table named password_reset_tokens
// with columns user_id, token, and expires_at

// Send the token to the user via SMS or display it on a secure webpage
// Make sure to include instructions on how to use the token to reset the password