form authentication, 3 requirements
i. If user click “save password”, the password will always be saved in the cookie unless he click “logout”.
ii. Otherwise, user need to input username and password when login.
iii. If the user just close the browser, he should be log out from the system, and need to use password to login
implementation:
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1,
user.GID.ToString(), DateTime.Now,DateTime.Now.AddMinutes(1),
chkRemember.Checked, roles);
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
if(chkRemember.Checked)
authCookie.Expires = DateTime.Now + (new TimeSpan(14,0,0,0));
Response.Cookies.Add(authCookie);
/********************************/
only if chkRemember.Checked, then set the logon cookie 2 weeks of validation.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment