Guest User

Untitled

a guest
Dec 26th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public void CreateCookie(string user, string password, bool isAuth = false)
  2. {
  3. const string cookiesName = "AUTH_COOKIES";
  4.  
  5. FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user, DateTime.Now, DateTime.Now.Add(FormsAuthentication.Timeout), isAuth, password, FormsAuthentication.FormsCookiePath);
  6.  
  7. HttpCookie cookies = new HttpCookie(cookiesName)
  8. {
  9. Value = FormsAuthentication.Encrypt(ticket),
  10. Expires = DateTime.Now.Add(FormsAuthentication.Timeout)
  11. };
  12.  
  13. Response.Cookies.Add(cookies);
  14. }
  15.  
  16. public UserInfo GetCookies(string encryptCookie)
  17. {
  18. var decryptCookies = FormsAuthentication.Decrypt(encryptCookie);
  19.  
  20. return new UserInfo() { Username = decryptCookies.Name, Password = decryptCookies.UserData };
  21. }
Add Comment
Please, Sign In to add comment