public void SetAuthenticationToken(string name, bool isPersistant, User userData) { string data = null; if (userData != null) data = new JavaScriptSerializer().Serialize(userData); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, name, DateTime.Now, DateTime.Now.AddYears(1), isPersistant, userData.UserId.ToString()); string cookieData = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieData) { HttpOnly = true, Expires = ticket.Expiration }; HttpContext.Current.Response.Cookies.Add(cookie); }
public User GetUserByUsernameAndPassword(User user) { return context.Users .Where(u => u.Username == user.Username & u.Password == user.Password).First(); }
public void CreateUser(User user) { context.Users.Add(user); context.SaveChanges(); }