Пример #1
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            if (this.rememberPasswordcheckBox.Checked) //判断记住密码是否被选中
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("Xml/UserInfo.xml");
                XmlElement userInfo    = doc.DocumentElement;     //获取根节点
                XmlNode    userAccount = userInfo["UserAccount"]; //获取根节点下的UserAccount节点
                userAccount.InnerText = this.accountNumberTbx.Text;
                XmlNode userPassword = userInfo["UserPassword"];  //获取根节点下的UserPassword节点
                userPassword.InnerText = this.passwordTbx.Text;
                XmlNode checkInfo = userInfo["CheckInfo"];        //获取根节点下的checkInfo节点
                checkInfo.InnerText = "yes";
                doc.Save("Xml/UserInfo.xml");
            }
            else
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("Xml/UserInfo.xml");
                XmlElement userInfo    = doc.DocumentElement;     //获取根节点
                XmlNode    userAccount = userInfo["UserAccount"]; //获取根节点下的UserAccount节点
                userAccount.InnerText = this.accountNumberTbx.Text;
                XmlNode userPassword = userInfo["UserPassword"];  //获取根节点下的UserPassword节点
                userPassword.InnerText = null;
                XmlNode checkInfo = userInfo["CheckInfo"];        //获取根节点下的checkInfo节点
                checkInfo.InnerText = "no";
                doc.Save("Xml/UserInfo.xml");
            }


            UserInfoService userService   = new UserInfoService();
            string          returnMessage = string.Empty;

            if (userService.CheckUserInfo(accountNumberTbx.Text.Trim(), passwordTbx.Text.Trim(), out returnMessage))//判断用户名密码是否正确
            {
                MessageBox.Show(returnMessage);
                this.DialogResult = DialogResult.OK;                             //向主界面返回值
                this.Close();
            }
            else
            {
                MessageBox.Show(returnMessage);
            }
        }
Пример #2
0
        ////验证用户session版
        //protected void CheckUserInfo(HttpContext context)
        //{
        //    UserInfo user = new UserInfo();
        //    //获取用户输入的用户名和密码.
        //    user.Account = context.Request.Form["account"];
        //    user.Password = context.Request.Form["password"];

        //    //校验用户名密码.
        //    UserInfoService userInfoService = new UserInfoService();
        //    string returnMessage = string.Empty;

        //    //判断用户名与密码
        //    UserInfo signUser = userInfoService.CheckUserInfo(user, out returnMessage);
        //    try
        //    {
        //        if(signUser.Authority=="admin")
        //        {
        //            context.Response.Write("<script>alert('" + "登录失败,您的权限为管理员权限,此系统仅允许普通权限工作人员登录!" + "');window.location = 'Index.html';</script>");
        //            return;
        //        }
        //        if (signUser.ID > 0)
        //        {
        //            context.Session["userInfo"] = signUser;
        //            context.Response.Write("<script>alert('" + "登录成功!" + "');window.location = 'HomePage.aspx';</script>");
        //        }
        //        else
        //        {
        //            context.Response.Write("<script>alert('" + "帐号或密码错误!" + "');window.location = 'Index.html';</script>");
        //        }
        //    }
        //    catch
        //    {
        //        context.Response.Write("<script>alert('" + "帐号或密码错误!" + "');window.location = 'Index.html';</script>");
        //    }
        // }


        /// <summary>
        /// 验证用户密码(cookie版)
        /// </summary>
        /// <param name="context"></param>
        protected void CheckUserInfo(HttpContext context)
        {
            UserInfo user = new UserInfo();

            //获取用户输入的用户名和密码.
            user.Account  = context.Request.Form["account"];
            user.Password = context.Request.Form["password"];

            //校验用户名密码.
            UserInfoService userInfoService = new UserInfoService();
            string          returnMessage   = string.Empty;

            //判断用户名与密码
            UserInfo signUser = userInfoService.CheckUserInfo(user, out returnMessage);

            try
            {
                if (signUser.Authority == "admin")
                {
                    context.Response.Write("<script>alert('" + "登录失败,您的权限为管理员权限,此系统仅允许普通权限工作人员登录!" + "');window.location = 'Index.html';</script>");
                    return;
                }
                if (signUser.ID > 0)
                {
                    context.Response.Cookies["userInfo"]["Account"]  = signUser.Account;
                    context.Response.Cookies["userInfo"]["AreaNum"]  = signUser.AreaNum.ToString();
                    context.Response.Cookies["userInfo"]["Password"] = signUser.Password;

                    context.Response.Write("<script>alert('" + "登录成功!" + "');window.location = 'HomePage.aspx';</script>");
                }
                else
                {
                    context.Response.Write("<script>alert('" + "帐号或密码错误!" + "');window.location = 'Index.html';</script>");
                }
            }
            catch
            {
                context.Response.Write("<script>alert('" + "帐号或密码错误!" + "');window.location = 'Index.html';</script>");
            }
        }