Click here to Skip to main content
14,668,434 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am currently creating a login form in visual c#, but i am facing problem on how to check if the user input username and password match with the USERNAME and PASSWORD in mysql table. I want the user to input a username and password in the text box then the program will search the table and if the username and password found. the program will display the main form, if not display error message.

Please help on how to accomplish this task i am beginner in c# or please help if where can i find a references or resources in c# programming and mysql as database.

Updated 4-Sep-20 6:04am
[no name] 13-Oct-12 9:01am
How is this a problem? Get the username and password from the user, connect to your database, and query the database to see if the username and password are valid.

Rate this:
Please Sign up or sign in to vote.

Solution 1

HI This will help you copy and paste it

SqlConnection con = new SqlConnection("Connection");
            SqlCommand cmd = new SqlCommand("select pwd,userName from LoginTable",con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            if (txtPassword.Text == dt.Rows[0]["pwd"].ToString() && txtUserName.Text == dt.Rows[0]["userName"].ToString())
            //Error display Msg
[no name] 13-Oct-12 9:11am
And this will allow the OP to connect to a MySql database?
Himanshu Yadav 13-Oct-12 9:12am
OP means
Himanshu Yadav 13-Oct-12 9:13am
asking regarding Connection String
Himanshu Yadav 13-Oct-12 9:18am
is this working ?
Luc Pattyn 4-Sep-20 19:21pm
That is horrible code.

1) whoever stores passwords as plain text should be fired right away.

2) for a single login, you think it is wise to read all known users from the database?

3) You don't need DataAdapters and DataTables for a simple read.

4) Objects that have a Dispose() method should be disposed of when done e.g. SqlConnection.

5) why would the user attempting to log in happen to be in the first row???

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100