Answer the question
In order to leave comments, you need to log in
How to properly organize token validation?
Hello.
How to properly organize token verification? Tokens will be used when registering, changing the user's email address, password recovery, deleting the profile, changing the status of the profile, and maybe some other functionality will be added further.
A few thoughts on this:
- Storage in the database in the user table, in the "token" column, when it is set, that is, the value, when not set, then NULL
- Storage in the database in a separate table of tokens (user_id, token, value, created_at ) , where all tokens will be stored, each token has a limited validity period (we go through the crown at a certain time and delete obsolete ones). The value column was introduced to save, for example, email, when changing it.
! The problem of storing in the database is determining which action the token belongs to. Those. what prevents me from substituting in the link to change the email token from password recovery. (or maybe I think so).
- Verification of the token without writing to the database, i.e. according to the principle we generate:
$token = md5('confirm_registration_' . $solt . $username); //$solt - произвольная hash-строка
/*делаем ссылку вида: http://mysite.dev?token={$token}&username={$username} .
При переходе по ней проверяем таким же образом*/
Answer the question
In order to leave comments, you need to log in
pfffffffff!
format: token only!
in the database in a tuple - all the parameters of this token.
Yes, and tokens are dangerous: the lifetime is 12 hours.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question