Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

Thanks.
Posted
Updated 4-Sep-20 6:04am
Comments
[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.

HI This will help you copy and paste it



C#
SqlConnection con = new SqlConnection("Connection");
            SqlCommand cmd = new SqlCommand("select pwd,userName from LoginTable",con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(da);
            if (txtPassword.Text == dt.Rows[0]["pwd"].ToString() && txtUserName.Text == dt.Rows[0]["userName"].ToString())
            {
                Response.Redirect("abc.aspx");
            }
            else
            { 
            //Error display Msg
            }
 
Share this answer
 
v2
Comments
[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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900