You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
5.7 KiB
150 lines
5.7 KiB
2 months ago
|
using MESClassLibrary.BLL.Log;
|
||
|
using MESClassLibrary.BLL.User;
|
||
|
using MESClassLibrary.Model;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Linq;
|
||
|
using System.Reflection;
|
||
|
using System.Text.RegularExpressions;
|
||
|
using System.Web;
|
||
|
using System.Web.UI;
|
||
|
using System.Web.UI.WebControls;
|
||
|
|
||
|
namespace MESWebSite
|
||
|
{
|
||
|
public partial class Login : System.Web.UI.Page
|
||
|
{
|
||
|
UserBLL userclass = new UserBLL();
|
||
|
UserModel md = new UserModel();
|
||
|
private static readonly string passwordPattern = @"^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^&*()_+/,.?<>:;'\{}=])[a-zA-Z0-9!@#$%^&*()_+/,.?<>:;'\{}=]{8,12}$";
|
||
|
|
||
|
protected void Page_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
if (!IsPostBack)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 登录按钮
|
||
|
/// </summary>
|
||
|
/// <param name="sender"></param>
|
||
|
/// <param name="e"></param>
|
||
|
protected void btnLogin_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string _loginName = this.LoginName.Text.Trim();
|
||
|
string _loginpassword = this.LoginPassword.Text.Trim();
|
||
|
//if (!IsValid(_loginpassword))
|
||
|
//{
|
||
|
// ClientScript.RegisterStartupScript(ClientScript.GetType(), "错误", "<script>alert('密码弱,请修改密码');</script>");
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// UserNameLogin(_loginName, _loginpassword);
|
||
|
//}
|
||
|
UserNameLogin(_loginName, _loginpassword);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public static bool IsValid(string password)
|
||
|
{
|
||
|
//使用正则表达式判断密码是否符合要求
|
||
|
return Regex.IsMatch(password, passwordPattern);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 登录方法
|
||
|
/// </summary>
|
||
|
/// <param name="_loginName"></param>
|
||
|
/// <param name="_loginpassword"></param>
|
||
|
public void UserNameLogin(string _loginName, string _loginpassword)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
int errTimes = 0;
|
||
|
md.Username = _loginName;
|
||
|
md.Password = _loginpassword;
|
||
|
DateTime lastLoginTime;
|
||
|
|
||
|
if (userclass.Login(md))
|
||
|
{
|
||
|
DataTable dt_user = new DataTable();
|
||
|
dt_user = userclass.SearchUserInfoByUserName(md.Username);
|
||
|
md.ErrTimes = 0;
|
||
|
|
||
|
userclass.UpdateUserInfo(md);
|
||
|
|
||
|
HttpCookie cookie = new HttpCookie("LoginUserInfo");
|
||
|
cookie.HttpOnly = true;
|
||
|
cookie["UserID"] = dt_user.Rows[0]["UserID"].ToString().Trim();
|
||
|
cookie["UserName"] = _loginName;
|
||
|
cookie["PassWord"] = _loginpassword;
|
||
|
cookie["RealName"] = HttpUtility.UrlEncode(dt_user.Rows[0]["RealName"].ToString().Trim(), System.Text.Encoding.UTF8);
|
||
|
//cookie.Expires = DateTime.Now.AddDays(14);
|
||
|
Response.Cookies.Add(cookie);
|
||
|
|
||
|
Response.Redirect("Manage/index.aspx", false);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DataTable dt_user = new DataTable();
|
||
|
dt_user = userclass.SearchUserInfoByUserName(md.Username);
|
||
|
if (dt_user != null && dt_user.Rows.Count > 0)
|
||
|
{
|
||
|
errTimes = Convert.ToInt32(dt_user.Rows[0]["ErrTimes"].ToString());
|
||
|
lastLoginTime = Convert.ToDateTime(dt_user.Rows[0]["LastLoginTime"].ToString());
|
||
|
|
||
|
if (errTimes >= 3 && (DateTime.Now - lastLoginTime).TotalMinutes < 15)
|
||
|
{
|
||
|
md.ErrTimes = errTimes + 1;
|
||
|
userclass.UpdateUserInfo(md);
|
||
|
ClientScript.RegisterStartupScript(ClientScript.GetType(), "错误", "<script>alert('用户已锁定');</script>");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
md.ErrTimes = errTimes + 1;
|
||
|
userclass.UpdateUserInfo(md);
|
||
|
ClientScript.RegisterStartupScript(ClientScript.GetType(), "错误", "<script>alert('用户名或密码错误,请重新输入');</script>");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#region 注销
|
||
|
//if (userclass.Login(md))
|
||
|
//{
|
||
|
// #region 下次自动登录-暂时注销
|
||
|
// //if (AutoLogin.Checked)
|
||
|
// //{
|
||
|
// // HttpCookie cookie = new HttpCookie("LoginUserInfo");
|
||
|
// // cookie["UserName"] = _loginName;
|
||
|
// // cookie["PassWord"] = _loginpassword;
|
||
|
// // cookie.Expires = DateTime.Now.AddDays(14);
|
||
|
// // Response.Cookies.Add(cookie);
|
||
|
// //}
|
||
|
// //Session.Add("LoginUserInfo", md);
|
||
|
// #endregion
|
||
|
|
||
|
// Response.Redirect("Manage/index.aspx", false);
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>alert('用户名或密码错误,请重新输入');</script>");
|
||
|
//}
|
||
|
#endregion
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|