Beispiel #1
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            PublicUtils utils = new PublicUtils();
            User        user  = utils.ReadIni();

            if (this.txtUserName.Text == user.UserName && this.txtPassword.Text == user.Password)
            {
                //1.生成一个动态口令 Token
                //2.将Token存储到Cookie中,存储用户名到Cookie中
                //3.服务器端存储一份Token。
                string SevenToken = "";
                bool   IsSeven    = this.CheckBox1.Checked;
                if (IsSeven)
                {
                    SevenToken = Guid.NewGuid().ToString();
                    //将Token写入服务器的文件中
                    utils.WriteIni(SevenToken);
                }
                WriteCookie(this.txtUserName.Text, SevenToken);
                Response.Redirect("Default.aspx");
            }
            else
            {
                Response.Write("<script>alert('登陆失败,情检查用户名或者密码是否有误!');</script>");
            }
        }
Beispiel #2
0
        private bool IsLoginOrSeven(out string UserName)
        {
            HttpCookie cookie = Request.Cookies["LoginInfo"];

            UserName = "";
            if (cookie != null)
            {
                PublicUtils utils = new PublicUtils();
                User        user  = utils.ReadIni();
                UserName = cookie.Values["UserName"];
                string SevenToken = cookie.Values["SevenTOken"];
                if (SevenToken != null)
                {
                    if (UserName == user.UserName && SevenToken == user.SevenToken)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (UserName == user.UserName)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                return(false);
            }
            return(false);
        }