用户界面中进行登录判断。输错三次禁止登陆(半小时),用数据库记录ErrorTimes。
1 namespace Login 2 { 3 /// <summary> 4 /// MainWindow.xaml 的交互逻辑 5 /// </summary> 6 public partial class MainWindow : Window 7 { 8 public MainWindow() 9 { 10 InitializeComponent(); 11 } 12 private void btnLogin_Click(object sender, RoutedEventArgs e) 13 { 14 //设置关卡一道道的判断。 15 if(txtLoginName.Text.Length<=0) 16 { 17 MessageBox.Show("用户名不能为空!"); 18 return; 19 } 20 if(pbpwd.Password.Length<=0) 21 { 22 MessageBox.Show("密码不能为空!"); 23 return; 24 } 25 DataTable dt = SqlHelper.ExecuteDataTable("select * from Table_2 where LoginName=@name", new SqlParameter("@name", txtLoginName.Text)); 26 if(dt.Rows.Count<=0) 27 { 28 textBlock3.Text = "该用户不存在!"; 29 return; 30 } 31 if(dt.Rows.Count>1) 32 { 33 textBlock3.Text = "用户名重复!"; 34 return; 35 } 36 //判断完毕取值 37 DataRow dr=dt.Rows[0]; 38 string pwd=(string)dr["LoginPassword"]; 39 Guid id=(Guid)dr["Id"]; 40 int errors=(int)dr["ErrorTimes"]; 41 if(errors>=3) 42 { 43 MessageBox.Show("错误输入次数太多,用户已锁定!"); 44 return; 45 } 46 if (pwd != pbpwd.Password) 47 { 48 //把登录用户相应的ErrorTimes++ 49 int ErrorTimesresult = SqlHelper.ExecuteNonQuery("update Table_2 set ErrorTimes=ErrorTimes+1 where Id=@id",new SqlParameter("@id",id)); 50 MessageBox.Show("登录失败!"); 51 } 52 else 53 { 54 MessageBox.Show("恭喜,登录成功!"); 55 } 56 } 57 } 58 }