2023年6月21日发(作者:)
C#winform实现登陆次数限制我们在⽹上登陆的时候有些⽹站在⽤户多次输错密码之后会⾃动把账户冻结,不能在进⾏登陆,⼩编这次做的winform程序就是要实现这种功能,具体内容如下功能⼀:根据数据库字段判断⽤户名和密码是否匹配;功能⼆:如果输⼊错误⾃动记录连续错误次数;功能三:如果⽤户登陆成功之后会⾃动清除错误次数,使⽤户仍然可以连续登陆3次;⾸先在winform窗体上拖⼊两个label和textbox,textbox分别命名为txbUserName,txbPassWord;然后在拖⼊⼀个button按钮;双击button按钮写按钮事件,代码如下:private void button1_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;")) { using (SqlCommand com = new SqlCommand()) { dText = "select * from T_Users where UserName=@username"; tion = con; (); (new SqlParameter("username", )); //(new SqlParameter("password", )); using (SqlDataReader read = eReader()) { if (()) { int errortimes = 32(inal("ErrorTimes")); //读取错误登陆次数 if (errortimes >= 3) //判断错误次数是否⼤于等于三 { ("sorry 你已经不能再登陆了!"); } else { string passwored = ing(inal("PassWord")); if (passwored == ) { ("登陆成功!"); ng(); //登陆成功把错误登陆次数清零 } else { ("登陆失败!"); (); //登陆失败把错误登陆次数加⼀ } } } } } } }
累加错误登陆次数函数:
public void leiji() { using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;")) { using (SqlCommand com = new SqlCommand()) { tion = con; dText = "update T_Users set ErrorTimes=ErrorTimes+1 where UserName=@username"; (new SqlParameter("username", )); (); eNonQuery(); } }
}清零错误登陆次数函数: public void qingling() { using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;")) { using (SqlCommand com = new SqlCommand()) { tion = con; dText = "update T_Users set ErrorTimes=0 where UserName=@username"; (new SqlParameter("username", )); (); eNonQuery(); } } }在button事件的代码中⼩编使⽤了using,关于using的⽤法与好处在《》中已经写过。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助。
2023年6月21日发(作者:)
C#winform实现登陆次数限制我们在⽹上登陆的时候有些⽹站在⽤户多次输错密码之后会⾃动把账户冻结,不能在进⾏登陆,⼩编这次做的winform程序就是要实现这种功能,具体内容如下功能⼀:根据数据库字段判断⽤户名和密码是否匹配;功能⼆:如果输⼊错误⾃动记录连续错误次数;功能三:如果⽤户登陆成功之后会⾃动清除错误次数,使⽤户仍然可以连续登陆3次;⾸先在winform窗体上拖⼊两个label和textbox,textbox分别命名为txbUserName,txbPassWord;然后在拖⼊⼀个button按钮;双击button按钮写按钮事件,代码如下:private void button1_Click(object sender, EventArgs e) { using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;")) { using (SqlCommand com = new SqlCommand()) { dText = "select * from T_Users where UserName=@username"; tion = con; (); (new SqlParameter("username", )); //(new SqlParameter("password", )); using (SqlDataReader read = eReader()) { if (()) { int errortimes = 32(inal("ErrorTimes")); //读取错误登陆次数 if (errortimes >= 3) //判断错误次数是否⼤于等于三 { ("sorry 你已经不能再登陆了!"); } else { string passwored = ing(inal("PassWord")); if (passwored == ) { ("登陆成功!"); ng(); //登陆成功把错误登陆次数清零 } else { ("登陆失败!"); (); //登陆失败把错误登陆次数加⼀ } } } } } } }
累加错误登陆次数函数:
public void leiji() { using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;")) { using (SqlCommand com = new SqlCommand()) { tion = con; dText = "update T_Users set ErrorTimes=ErrorTimes+1 where UserName=@username"; (new SqlParameter("username", )); (); eNonQuery(); } }
}清零错误登陆次数函数: public void qingling() { using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;")) { using (SqlCommand com = new SqlCommand()) { tion = con; dText = "update T_Users set ErrorTimes=0 where UserName=@username"; (new SqlParameter("username", )); (); eNonQuery(); } } }在button事件的代码中⼩编使⽤了using,关于using的⽤法与好处在《》中已经写过。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助。
发布评论