Need urgent help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need urgent help

amit2usaamit2usa Posts: 3Member
Hi all,
I am having problem with username string matching ie Upper or lower case.It is accepting username in Small also and in caps alsO and Its accepting the space too !!! whenever i am providing the correct username and password.
I am giving u here the code ,pls reply with correct answer.

private void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("connection string");
string str;
str=("Select * from Logins where Username='"+txtUsername.Text+"' and Password='"+txtPassword.Text+"' ");
SqlCommand cmd = new SqlCommand(str,con);
con.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (((dt.Rows.Count > 0)&&(txtUsername.Text!=txtUsername.Text.ToLower()))&&(txtPassword.Text!=txtPassword.Text.ToUpper()))
{
MessageBox.Show("WELCOME");
}
else
{

MessageBox.Show("INVALID USERNAME/password");
}
con.Close();
}


Sign In or Register to comment.