예제 #1
0
        protected void checkUseInfo()
        {
            string username = Request.Form["txtName"];
            string password = Request.Form["txtPwd"];
            //校验用户名和密码
            string          msg             = String.Empty;
            UserInfo        userInfo        = null;
            UserInfoService userInfoService = new UserInfoService();

            if (userInfoService.ValidateUseInfo(username, password, out msg, out userInfo))
            {
                //判断用户是否勾选自动登录(如果有的话需要记录cookie)
                if (!string.IsNullOrEmpty(Request.Form["autoLogin"]))
                {
                    HttpCookie cookie1 = new HttpCookie("username", username);
                    HttpCookie cookie2 = new HttpCookie("password", Md5Common.GetMd5String(Md5Common.GetMd5String(password)));
                    cookie1.Expires = DateTime.Now.AddDays(30);
                    cookie2.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(cookie1);
                    Response.Cookies.Add(cookie2);
                }

                //保存用户信息
                Session["userInfo"] = userInfo;
                Response.Redirect("UserInfoAsp.aspx");
            }
            else
            {
                Msg = msg;
            }
        }
예제 #2
0
        protected void checkCookieInfo()
        {
            if (Request.Cookies["username"] != null && Request.Cookies["password"] != null)
            {
                string username = Request.Cookies["username"].Value;
                string password = Request.Cookies["password"].Value;

                //查询是否有用户名,然后是否有密码
                UserInfoService userInfoService = new UserInfoService();
                UserInfo        userInfo        = userInfoService.GetUserInfo(username);
                if (userInfo != null)
                {
                    string doubleMd5Pwd = Md5Common.GetMd5String(Md5Common.GetMd5String(userInfo.UserPass));
                    if (doubleMd5Pwd == password)
                    {
                        Session["userInfo"] = userInfo;
                        Response.Redirect("UserInfoAsp.aspx");
                    }
                    Response.Cookies["cookie1"].Expires = DateTime.Now.AddDays(-1);
                    Response.Cookies["cookie2"].Expires = DateTime.Now.AddDays(-1);
                }
            }
        }