User-2054057000 posted
You can do these things:
- Generate a new Guid, and store it in the database.
- In the email your link should contain the same guid in the query string.
- Now in your web page you should check if the guid matches then you log the user automatically to his account.
Explanation:
- You can create a new table that stores the guid and the user id
- Before you send the email to a user you store that guid with user id in the table. The table structure is given below:
-
User Id |
Guid |
1 |
0f8fad5b-d9cb-469f-a165-70867728950e |
- Now when you end the email give a login to your account link that contains the same guid in query string.
<a href="http://www.yourwebsite.com/login/?guid=0f8fad5b-d9cb-469f-a165-70867728950e">Login to your account</a>
So when the user clicks the link he reaches the website's login page. In that login page you extract the guid value from query string. Then you match the guid with the guid column of the table. So you get the User Id of the person.
Now you know which user has clicked the link and you do the automatic login.
Some website also adds the expiry time of the guid. For this they add a new
ExpiryTime column on the table. And this helps them to prevent users to use the link for login after the exprity time has reached.
I hope I am clear in my explanation.
Thanks You,
YOGI