• 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);
                }
            }
  • 相关阅读:
    Java反射机制
    dd命令
    分区工具fdisk,gdisk,parted
    硬盘初识
    shell脚本之算术运算和逻辑运算
    linux防火墙简单的使用
    压缩解压打包工具基础
    find命令基础讲解
    个人数据备份方案
    数据库的表名字段名大小写问题
  • 原文地址:https://www.cnblogs.com/RambleLife/p/9081389.html
Copyright © 2020-2023  润新知