I am creating a web app where in one of the functionality I need is to automatically login the user for which cookie is not expired yet. Below code is my starting point -
HttpCookie curCookie = Request.Cookies[".ASPXAUTH"];
if (curCookie != null)
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(curCookie.Value);
var userName = ticket.Name;
using (MyDBContext db = new MyDBContext())
{
// what to do here?
}
}
If the cookie has expired, then I can't help it. But if it has not, then I can think of three approaches to follow -
1) I can connect to db (webpages_Membership) and get corresponding password, decrypt and then attempt to login.
2) I can store the hashed password with the cookie and retrieve it and login.
3) I can store the hashed password in UserProfile table and as I already have a dbset in my code, I can use it to query and login.
I am new to ASP.NET MVC and a little confused about which is the right approach for me. If there are any in-built functions to retrieve passwords, please let me know.