日期:2014-05-18 浏览次数:20868 次
int times = 0; bool result = false; while (!result && times < 3) { string username = xxx; string password = yyy; result = login(username, password); times++; }
------解决方案--------------------
代碼被注釋了,還能夠執行?第一次聽說。
------解决方案--------------------
一般3次锁定,都是配合数据库实现的。加一列记录错误次数
------解决方案--------------------
pivate int errCnt=0; private void btnLogin_Click(object sender, EventArgs e) { AdminSys aSys=new AdminSys(); string adminName = this.txtAdminName.Text.Trim(); string adminPwd = this.txtAdminPwd.Text.Trim(); aSys = AdminSysManager.QueryAdminSysByAdminNameAndAdminPwd(adminName,adminPwd); if (aSys != null && aSys.AdminName == adminName && aSys.AdminPwd == adminPwd) { MainForm mf = new MainForm(); mf.Show(); mf.Close += (sd,arg)=>{ this.Close(); }; this.Visible = false; } else { errCnt++; if(errCnt>3) throw new Exception("超过3次登录错误!"); else MessageBox.Show("用户名或者密码错误,请重新登录!"); } }
------解决方案--------------------
winform的话用个变量来记录登陆次数,比如:
private int count = 0; ... else { if (count < 3) { txtAdminName.Text = ""; txtAdminName.Focus(); txtAdminPwd.Text = ""; count++; } else { MessageBox.Show("aaa"); } }