Im trying to make my own FormsAuthentication in an ASP.NET MVC 4 application and I have seen two different ways of creating my authcookie and I was wondering if one of them is having any disadvantages or if it is safe to use them both and are there any other differences I should know about before I decide witch to use?
the first one is
FormsAuthentication.SetAuthCookie(userName, rememberMe);
the other one is a bit longer
var authTicket = new FormsAuthenticationTicket(
1,
userName,
DateTime.Now,
DateTime.Now.AddMinutes(30),
rememberMe,
"Users"
);
var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
HttpContext.Current.Response.Cookies.Add(authCookie);
please enlighten me about this decision
Actually, the first method calls the second method. I have taken the source of the
SetAuthCookieto show this, but removed some lines to keep it relevant: