Пример #1
0
        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);
        }
Пример #2
0
 public User GetUserByUsernameAndPassword(User user)
 {
     return context.Users
         .Where(u => u.Username == user.Username & u.Password == user.Password).First();
 }
Пример #3
0
 public void CreateUser(User user)
 {
     context.Users.Add(user);
     context.SaveChanges();
 }