Click here to Skip to main content
15,905,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using visual studio and access 2012.
I did a login form with passwordbox and username textbox.
I want to check if the username password exists in the database.
I did this.

C#
cmd.CommandText = "SELECT * FROM LOGIN WHERE username= '"+UserName+"' AND password='"+PassWord+"'";
            
           // cmd.CommandText = "INSERT INTO Login VALUES('CHEKH','CHEKH')";
            OleDbDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                MessageBox.Show("ID exists");
            }


It worked but I don't know how. Is this the correct way?
Posted
Updated 28-Apr-13 8:01am
v2
Comments
[no name] 28-Apr-13 14:02pm    
You should never create SQL statements with string concatenation. Other than that, if it worked then how could not be correct?
missak boyajian 28-Apr-13 17:13pm    
What should I use instead?

1 solution

No, it's not correct, in many ways. Not the least of which is that you're storing passwords unencrypted in the database. If your database gets hacked, you just screwed all of your customers into changing their passwords everywhere else they have accounts.

Read these[^].

and these[^].
 
Share this answer
 
v2
Comments
missak boyajian 28-Apr-13 17:12pm    
Thanks for the answer. It seems a little bit complicated but I will see what I can do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900