namespace 登录锁定 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if(IsLock(txtName.Text))//判断锁定没 { MessageBox.Show("锁了"); } else { ClearLoginName(txtName.Text);//清了 if (IsOk(txtName.Text,txtPwd.Text)) { //登录成功了 MessageBox.Show("成功了"); } else { MessageBox.Show("登录失败了"); LockedLoginName(txtName.Text); } } } private void LockedLoginName(string p) { string sql = "update Users SET ErrorCount=ErrorCount+1 ,LastLoginTime=getdate() WHERE [email protected]"; SqlHelper.ExecuteNonQuery(sql,new SqlParameter("@name",p)); } private bool IsOk(string p, string p_2) { string sql = "select count(*) from Users where [email protected] AND [email protected]"; return Convert.ToInt32(SqlHelper.ExecuteScalar(sql, new SqlParameter("@name", p), new SqlParameter("@pwd", p_2))) > 0 ? true : false; } private void ClearLoginName(string p) { string sql = "UPDATE Users SET ErrorCount=0 ,LastLoginTime=getdate() WHERE [email protected] and ErrorCount>=3"; int n= SqlHelper.ExecuteNonQuery(sql,new SqlParameter("@name",p)); } private bool IsLock(string p) { string sql = "select count(*)from Users where [email protected] AND ErrorCount>=3 AND datediff(minute,LastLoginTime,getdate())<=15"; object obj= SqlHelper.ExecuteScalar(sql,new SqlParameter("@name",p)); return Convert.ToInt32(obj) > 0 ? true : false; } } }
时间: 2024-11-08 21:56:23