Your circuit really works, but there are some points that could be improved. But first to your original question about the deadline:
Ask the opposite question: why does the token remain valid indefinitely?
There is no advantage when after two years you can click the reset -link link, or the user clicks the link after about an hour, or he probably forgot about the link (and can request a new one if necessary), On the other hand, the ability to read emails is not necessarily means that the attacker must hack into an email account, for example, an open email client in the office, a lost mobile phone, backup to a (lost) USB drive ...
The most important improvement is that you have to store the hash for the token in your database. Someone who has access to the database (SQL injection) might otherwise require a reset password for any email address that he likes, but because he can see the new token, he can use it to set your own password.
Then I saved this reset data in a separate table. There you can save the user ID, the hashed token, the expiration date and information about whether the link has already been used. Then the user is not in special condition.
Perhaps I misunderstood this point, but the reset link should point to a special page to reset the password. When the user goes to the login page, there should be no special processing, on the login page it should not be known that there is a pending password - reset.
The reset marker should be unpredictable, this can be achieved in the best way with truly random code read from a random operating system source.
martinstoeckli
source share