Exemple #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            DataClassesDataContext context = new DataClassesDataContext(new SqlUtil().getConnectionStringByName("SQLServer_connection_string"));
            var account = context.Accounts.Where(x => x.Username.Trim().Equals(tbUser.Text)).FirstOrDefault();

            if (account != null)
            {
                if (EncodeMD5.VerifyMd5Hash(MD5.Create(), tbPass.Text, account.Password))
                {
                    Session["acc"]      = account.Role;
                    Session["name"]     = account.Name;
                    Session["username"] = account.Username;
                    Response.Redirect("Home.aspx");
                    return;
                }
            }
            lbnoti.Text = "Login failed";
        }
Exemple #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Account a = new Account()
            {
                Username = tbUserName.Text,
                Password = EncodeMD5.GetMd5Hash(MD5.Create(), tbPass.Text),
                Name     = tbName.Text,
                Role     = "customer"
            };
            DataClassesDataContext context = new DataClassesDataContext(new SqlUtil().getConnectionStringByName("SQLServer_connection_string"));

            context.Accounts.InsertOnSubmit(a);
            try
            {
                context.SubmitChanges();
                lbthongbao.Text = "Register successfully, you can login with this account!";
            }
            catch (Exception)
            {
                lbthongbao.Text = "Register failed, check another username!";
            }
        }