Reputation: 11911
I have a database table with 4 columns (email, token, tokenDate (DateTime), isOnline (bool))
What I am trying to do in ASP.NET MVC is have an application where the user goes to a page like this Home/[email protected]
and when they goto the page, they are login, now what I could do it when they goto the page is this:
isOnline
to truetokenDate
to DateTime.Now
token
and set that as tokenAnd when someone else (or the same person) with the same email tries to goto the page
isOnline
is marked as true
and the cookie does not exist and if it does check against the one in the database, if fails boot them out, if success, they can enter.My question is what token would I want to create so they original user is still authenticated so if they close their browser or goto another page they can still goto the main page where they authenticated?
Upvotes: 0
Views: 725
Reputation: 6607
User goes to a page like this Home/[email protected]
or User Types email in a text box
STEP 1:
DateTime.UtcNow
so that you can display later into local time of
user. Step 2:
Now when user goes to Home/SomeOtherPage
or the authentication page Home/[email protected]
Check if cookie with the name exist , if exist get the email and token values from cookie and check against the value in database , if token matches for the email then user is authenticated.
Edit cookie and Set another value in cookie saying if user is authenticated, So next time when user visits check the value of authenticated as this would eliminate hitting database again if user visit pages again.
Note:
It would be better if you could encrypt the email while setting it in the cookie.
Upvotes: 1