Password reset links – random strings vs. signed tokens?
I see two ways of handling them:
* Generate a random string, for example with uuid4. Store it in the database with the user and send it in a link to the user. When the form is filled in and sbumitted the random string will be the payload and matched to the user. The string is then removed from the database so it can only be used once. It should also have an expiry date. Pros: Simple and safe Cons: Have to store it in the database
* Generating a signed token. From the username or id and a timestamp a signed token is generated with a secret key. This is the link sent to the user. When the user submits the token is decrypted back and the user and timestamp retrieved and validated. The issue here is that it can be reused so you have to store the old password as well. Pros: Nothing needs to be stored in the database. Cons: Riskier? Is it a bad idea to send the old, encrypted password in the link? It is encrypted.