コード例 #1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DataAccessLayer loginDAL = new DataAccessLayer();
            string          username = txtUsername.Text;
            string          password = Security.GetHash256(txtPassword.Text, txtUsername.Text);


            if (loginDAL.VerifyAdminUser(username, password))
            {
                lblErrorMessage.Visible = false;
                HttpCookie cookie = new HttpCookie("user");
                cookie.Values["username"]    = loginDAL.getUsername();
                cookie.Values["userprofile"] = loginDAL.getUserProfile();
                cookie.Expires = DateTime.Now.AddDays(3);

                Response.Cookies.Add(cookie);
                Response.Redirect("DashboardAdmin.aspx");
            }
            else if (loginDAL.VerifyElectorUser(username, password))
            {
                lblErrorMessage.Visible = false;
                HttpCookie cookie = new HttpCookie("user");
                cookie.Values["username"]    = loginDAL.getUsername();
                cookie.Values["userprofile"] = loginDAL.getUserProfile();
                cookie.Expires = DateTime.Now.AddDays(3);

                Response.Cookies.Add(cookie);
                Response.Redirect("DashboardElectors.aspx");
            }
            else if (loginDAL.VerifyCandidateUser(username, password))
            {
                lblErrorMessage.Visible = false;
                HttpCookie cookie = new HttpCookie("user");
                cookie.Values["username"]    = loginDAL.getUsername();
                cookie.Values["userprofile"] = loginDAL.getUserProfile();
                cookie.Expires = DateTime.Now.AddDays(3);

                Response.Cookies.Add(cookie);
                Response.Redirect("DashboardCandidate.aspx");
            }
            else
            {
                lblErrorMessage.Visible   = true;
                lblErrorMessage.Text      = "Please enter valid Username or Password!";
                lblErrorMessage.ForeColor = System.Drawing.Color.Red;
            }
        }