zoukankan      html  css  js  c++  java
  • ASP.NET登录验证

       protected void btnLogin_Click(object sender, EventArgs e)
            {
                string username = txtUserName.Value.Trim();
                string userpassword = txtUserPassword.Value.Trim();
    
                if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(userpassword))
                {
                    Common.MessageBox.Show(this, "账号和密码不能为空!");
                }
                else
                {
                    string ip = Request.UserHostAddress;
                    BLL.ProxyInfo bllMember = new ProxyInfo();
                    string encrytpswd = DimoNetwork.Common.DEncrypt.TextEncrypt.MD5EncryptPassword(userpassword);
                    int reuslt;
                    Model.UserInfo userInfo= bllMember.ProxyLogin(username, encrytpswd, ip, out reuslt);
                    if (mProxyInfo != null)
                    {
                        //判断用户是否被冻结
                        if (userInfo.freezeState)
                        {
                            Common.MessageBox.Show(this, "您的账号已被冻结,请联系你的上级代理!");
                        }
                        else
                        {
                            Common.Cache.DimoCache.Default.Save<Common.Cache.SessionCache>("MemberSession", userInfo);
                            Common.MessageBox.ShowAndRedirects(this.Page, "", "main.aspx");
                        }
                    }
                    else
                    {
                        AddLoginErrorCount();
                        if (GetLoginErrorCount() >= 5)
                        {
                            Common.MessageBox.Show(this, "账号或密码错误次数过多,账号被锁定20分钟,请20分钟后重试!");
                            txtUserName.Value = "";
                            txtUserPassword.Value = "";
                            btnLogin.Visible = false;
                        }
                        else
                        {
                            Common.MessageBox.Show(this, "账号或密码错误!");
                        }
                    }
                }
            }
            /// <summary>
            /// 获得登陆错误次数
            /// </summary>
            /// <returns></returns>
            protected int GetLoginErrorCount()
            {
                int logincount = 0;
                object logincountcache = Common.Cache.Default.Get<Common.Cache.SessionCache>(lockcachekey);
                if (logincountcache != null)
                {
                    logincount = Convert.ToInt32(logincountcache);
                }
                return logincount;
            }
      /// <summary>
            /// 修改用户登录错误次数
            /// </summary>
            protected void AddLoginErrorCount()
            {
                object logincountcache = Common.Cache.DimoCache.Default.Get<Common.Cache.SessionCache>(lockcachekey);
                if (logincountcache != null)
                {
                   int logincount = Convert.ToInt32(logincountcache);
                   Common.Cache.Default.Save<Common.Cache.SessionCache>(lockcachekey,logincount + 1);
                }
            }
  • 相关阅读:
    文件上传漏洞总结篇
    python 构造mysql爆破器
    python写exploit采集器
    文件包含漏洞总结
    python Flask篇(一)
    Python写一个目录检索器
    python爬搜狗微信获取指定微信公众号的文章
    python打造文件包含漏洞检测工具
    python打造漏洞补丁缺少检测
    表单
  • 原文地址:https://www.cnblogs.com/RambleLife/p/9081389.html
Copyright © 2011-2022 走看看