'How to ensure username and password match case sensitivity
While testing this code I have found out that it doesn't matter if it's uppercase or lowercase the check still passes. I've tried a couple of methods with EQUALS or .Equals(), but I just cant get my head around it.
if (isValid())
{
using (SqlConnection conn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\DAVER\OneDrive\Desktop\Project\LoginDatabase.mdf;Integrated Security=True"))
{
string query = "SELECT * FROM Login WHERE Username '" + txtBoxUserName.Text.Trim() +
"' AND Password '" + txtPassword.Text.Trim() + "'";
SqlDataAdapter sqlData = new SqlDataAdapter(query, conn);
DataTable data = new DataTable();
sqlData.Fill(data);
if (data.Rows.Count == 1)
{
ControlID.txtBoxUserName = txtBoxUserName.Text;
ControlID.txtPassword = txtPassword.Text;
PopUp pop = new PopUp();
this.Hide();
pop.Show();
}
else
{
MessageBox.Show("Username and/or Password Not Recognised!", "Error");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
