Here Is My C# code:
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");
}
}
}
How to validate that password should contain atleast a number and a special character when login button is clicked.