ASP.NET登录验证
程序员文章站
2022-03-06 23:47:16
protected void btnLogin_Click(object sender, EventArgs e) { string username = txtUserName.Value.Trim(); string userpassword = txtUserPassword.Value.Tr... ......
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); } }