private void btnCustomLogin_Click(object sender, EventArgs e)
{
if (txtpassword.Text != string.Empty || txtusername.Text != string.Empty)
{
SetValueForText1 = txtusername.Text;
cmd = new SqlCommand("select * from Login where Username='" + txtusername.Text + "' and Password='" + txtpassword.Text + "'", cn);
dr = cmd.ExecuteReader();
if (dr.Read())
{
dr.Close();
this.Hide();
Home home = new Home();
home.ShowDialog();
}
else
{
dr.Close();
this.Alert("No Account available with\nthis Username and Password.", Form_Alert.enmType.Error);
}
}
else
{
this.Alert("Please enter value in all field.", Form_Alert.enmType.Error);
}
}
How do I make both the username and password case sensitive?
Sachin SinghPosted Nov 5, 2021, 10:41 AM
Sachin SinghPosted Nov 5, 2021, 11:43 AM
Srinivasan RamamoorthiPosted Nov 5, 2021, 10:41 AM
If you want to retain case sensitive in sql query, try comparing using binary values as mentioned in my previous answer. It will convert the characters to binary and do comparison. Lower case and Upper case will have different binary values so you will be able to compare with case sensitive values. For password you have to retain case sensitivity by using binary comparison.
Samuel TohPosted Nov 5, 2021, 10:34 AM
Srinivasan RamamoorthiPosted Nov 5, 2021, 10:28 AM
CAST(Username as varbinary(100)) = CAST(@Username as varbinary))2. Use BINARY_CHECKSUMSachin SinghPosted Nov 5, 2021, 10:24 AM