Exemplo n.º 1
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {

            userBLL ubll = new userBLL();
            string username = UserName.Text.Trim(), password = Password.Text.Trim();
            System.Diagnostics.Debug.WriteLine("我是账户名" + username);

            HttpCookie oldcookie = Request.Cookies["preferences"];
            if (oldcookie == null)
            {

                //测试登录功能


                int[] result = ubll.login(username, password);
                if (result[0] >= 1)
                {
                    info = "登陆成功";
                    HttpCookie cookie = new HttpCookie("Preferences");

                    cookie["username"] = username;

                    cookie["userid"] = result[0].ToString();
                    cookie["role"] = result[1].ToString();
                    Session["userid"] = result[0].ToString();
                    Session["role"] = result[1].ToString();
                    Session["username"] = username;
                    Response.Cookies.Add(cookie);
                    //cookie有效1个月
                    cookie.Expires = DateTime.Now.AddMonths(1);
                    //重定向到主页
                    Response.Redirect("~/Default.aspx");
                }
                else
                    if (result[0] == -1)
                    { info = "密码错误"; Label1.Text = info; UpdatePanel1.Update(); }
                    else
                    { info = "账号不存在"; Label1.Text = info; UpdatePanel1.Update(); }

                System.Diagnostics.Debug.WriteLine(info);
            }

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string oldpsw = TextBox1.Text.Trim();
            string newpsw = TextBox2.Text.Trim();
            userBLL ubll = new userBLL();
            string username = Session["username"].ToString().Trim();
            int result = ubll.login(username, oldpsw)[0];
            if (result >= 1)
            {
                int userID = Convert.ToInt32(Session["userid"]);
                if (ubll.changePsw(userID, newpsw) >=1)
                { Label4.Text = "修改成功"; UpdatePanel1.Update(); }
            }
            else
            {
                Label4.Text = "旧密码错误"; 
                UpdatePanel1.Update(); 
            }

        }