Example #1
0
        protected void Create_Click(object sender, EventArgs e)
        {
            string name = ctrLoginTB.Text;

            string pass1 = ctrPassword1TB.Text;
            string pass2 = ctrPassword2TB.Text;



            if (pass1 == pass2)
            {
                HospitalDataBaseEntities2 context = new HospitalDataBaseEntities2();

                if (context.Users.AsNoTracking().FirstOrDefault(u => u.Name == name) is null)
                {
                    context.Users.Add(new User {
                        Name = name, Password = CryptoProvider.GetMD5Hash(pass1 + "31415")
                    });
                    context.SaveChanges();

                    Response.Redirect("Login.aspx");
                }
            }
        }
Example #2
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string name = ctrLoginTB.Text;
            string pass = CryptoProvider.GetMD5Hash(ctrPasswordTB.Text + "31415");

            HospitalDataBaseEntities2 context = new HospitalDataBaseEntities2();

            context.Users.AsNoTracking().FirstOrDefault(u => u.Name == name && u.Password == pass);

            if (context.Users.AsNoTracking().FirstOrDefault(u => u.Name == name && u.Password == pass) != null)
            {
                HttpCookie cookieName = new HttpCookie("name", ctrLoginTB.Text);
                HttpCookie cookieSign = new HttpCookie("sign", CryptoProvider.GetMD5Hash(ctrPasswordTB.Text + "31415"));

                Response.Cookies.Add(cookieName);
                Response.Cookies.Add(cookieSign);

                Response.Redirect("Home.aspx");
            }
            else
            {
                ErrorLabel.Visible = true;
            }
        }