【发布时间】:2017-09-06 12:06:16
【问题描述】:
这是我的 C# 代码:
private void btnLogin_Click(object sender, EventArgs e)
{
if (Regex.IsMatch(txtPassword.Text, @"(!|@|#)"))
{
MessageBox.Show("Password Must Contain at least a special character");
}
else
{
SqlConnection con = new SqlConnection("Data Source=Sumit;Initial Catalog=BroadDB;Integrated Security=True");
string sql = "select * from tblLogin where username=@username and password=@password";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@username", txtUsername.Text);
cmd.Parameters.AddWithValue("@password", txtPassword.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Form2 obj = new Form2();
obj.Show();
}
else
{
MessageBox.Show("Invalid Data");
}
}
}
当点击登录按钮时,如何验证密码至少应包含一个数字和一个特殊字符。
【问题讨论】: