I have a website like SO. Also there is a link in the Login page named forgot password which sends an email to reset the password. As you know that email contains a link like this:
http://www.example.com/resetpassword?token={what thing can be here?}
As you see, my question is about the value of that token.
Here is my table structure:
// users
+----+--------+---------------+---------------+------------------------------+
| id | name | password | cookie | /* and some other columns */ |
+----+--------+---------------+---------------+------------------------------+
| 1 | jack | d404559f60... | 0c2c62b9dc... | /* anything */ |
+----+--------+---------------+---------------+------------------------------+
password
column:
$password = $_POST['password']; // ex: 1234
$password = hash('sha512',$pass); // d404559f602eab6fd602ac7680dacbfaadd13630335e951f097af3900e9de176b6db28512f2e000b9d04fba5133e8b1c6e8df59db3a8ab9d60be4b97cc9e81db
cookie
column:
$email = 'jack.1998@gmail.com';
$cookie = hash('sha512', $email.$password); // 0c2c62b9dc9bdf72ce4c845cc400dcc96ebf9898e1b3e821c7d99cae3dbe486e3b0534ccd73903dfc03cb4b424b39fdd67b68724708ddfd56424bf14ee4507bf
As I read in this and this answers: That token should be a random string. And I have to store it into database (for validating).
What's my question? Can I use the value of $cookie
as that token?
Note1: I've used $password
variable to generate $cookie
value, because I want to log-out an user from all devices when he changes his password.
Note2: I don't want any expire time for that reset-password-link (that I've sent into email).