Пример #1
0
        protected void ButtonRegister_Click(object sender, EventArgs e)
        {
            var pass = this.TextBoxPassword.Text;
            var user = this.TextBoxUsername.Text.ToLower();
            var nick = this.TextBoxNickName.Text;
            using (var context = new CookiesEntities())
            {
                var userEntity = context.Users.FirstOrDefault(u => u.UserName == user);
                if (userEntity == null)
                {
                    var newUser = new User
                    {
                        Password = pass,
                     UserName = user,
                        NickName = nick
                    };

                    context.Users.Add(newUser);
                    context.SaveChanges();
                    HttpCookie cookie = new HttpCookie("NickName", newUser.NickName);
                    cookie.Expires = DateTime.Now.AddMinutes(1.0);
                    Response.Cookies.Add(cookie);
                    Response.Redirect("Hidden.aspx");
                }
            }
        }
Пример #2
0
 protected void ButtonLogin_Click(object sender, EventArgs e)
 {
     var pass = this.TextBoxPassword.Text;
     var user = this.TextBoxUsername.Text.ToLower();
     using(var context = new CookiesEntities())
     {
         var userEntity = context.Users.FirstOrDefault(u => u.UserName == user && u.Password == pass);
         if (userEntity != null)
         {
             HttpCookie cookie = new HttpCookie("NickName", userEntity.NickName);
             cookie.Expires = DateTime.Now.AddMinutes(1.0);
             Response.Cookies.Add(cookie);
             Response.Redirect("Hidden.aspx");
         }
     }
 }