密码错误3次,30分钟内无法登录源码
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace 用户登录
{
public partial class Form1 : Form
{
publicForm1()
{
InitializeComponent();
}
///<summary>
///增加错误次数的方法
///</summary>
privatevoid IncErrorTime()
{
stringConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using(SqlConnection conn = new SqlConnection(ConnStr))
{
using(SqlCommand updateCmd =conn.CreateCommand())
{
updateCmd.CommandText = "update T_Admin set errortime=errortime+1 whereUsername=@username";
updateCmd.Parameters.Add(new SqlParameter("username", txtUserName.Text));
conn.Open();
updateCmd.ExecuteNonQuery();
}
}
}
///<summary>
///错误次数清0
///</summary>
privatevoid NotErrorTime()
{
stringConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using(SqlConnection conn = new SqlConnection(ConnStr))
{
using(SqlCommand updateCmd =conn.CreateCommand())
{
updateCmd.CommandText = "update T_Admin set errortime=0 whereUsername=@username";
updateCmd.Parameters.Add(new SqlParameter("username", txtUserName.Text));
conn.Open();
updateCmd.ExecuteNonQuery();
}
}
}
///<summary>
///密码错误3次,记录当前时间加30分钟
///</summary>
privatevoid IncLoginTime()
{
stringConnStr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using(SqlConnection conn = new SqlConnection(ConnStr))
{
using(SqlCommand updateCmd =conn.CreateCommand())
{
updateCmd.CommandText = "update T_Admin set logintime=@logintime whereUsername=@username";
DateTimelogintime = DateTime.Now.AddMinutes(30);
updateCmd.Parameters.Add(new SqlParameter("username", txtUserName.Text));
updateCmd.Parameters.Add(new SqlParameter("logintime", logintime.ToString()));
conn.Open();
updateCmd.ExecuteNonQuery();
}
}
}
privatevoid button1_Click(objectsender, EventArgs e)
{
补充:综合编程 , 安全编程 ,