Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

mysql not working for login?

c# mysql login

Best Answer tavichh, 12 September 2013 - 08:38 PM

Nevermind I had a friend fix it for me. Thank you all for contributing to this thread!

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts

Posted 26 August 2013 - 09:34 AM

I re-did this post. I hope someone can find this error.

 

I go to enter in my username and password and it keeps on saying invalid credentials when its not. It's apparently the wrong credentials.

 public bool tryLogin(string username, string password)
        {
            MySqlConnection con = new MySqlConnection("server=xxxxx;database=xxxxxxx;userid=xxxxxxx;password=xxxxxxxxxxxxxxxx;");
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM test WHERE username = '" + username + "' AND password = '" + password + "';");
            cmd.Connection = con;
 
            con.Open();
 
            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read() != false)
            {
                if (reader.IsDBNull(0) == true)
                {
                    cmd.Connection.Close();
                    cmd.Dispose();
                    return false;
                }
                else
                {
                    cmd.Connection.Close();
                    cmd.Dispose();
                    return true;
                }
            }
            else
            {
                return false;
            }
        }

 private void button1_Click(object sender, RoutedEventArgs e)
        {
            
            if (tryLogin(txtUsername.Text, txtPassword.Text) == true)
            {
                MessageBox.Show("it works");
                UCP ucp = new UCP();
                ucp.Show();
            }
            else
            {
                MessageBox.Show("Invalid Credentials");
            }
        }
 

Edited by Thryckz, 02 September 2013 - 04:07 PM.

Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#2 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts

Posted 02 September 2013 - 03:57 PM

bump, 

I need help with this guys :(


Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#3 Barnsite

Barnsite

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 258 posts

Posted 03 September 2013 - 02:31 AM

Hi, I'm not sure about the logic of the two if statements... could I make a suggestion?

 

I would change the sql to be a count, i.e. SELECT COUNT(*) FROM... etc you will then only have to do one test for zero / one, rather than these tests for null / no rows.


There are two ways to write error-free programs; only the third one works.

#4 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts

Posted 03 September 2013 - 07:20 AM

If this is a project for school, leave the sql alone.  If this is for some kind of enterprise program, you better rethink that whole sql statement.

 

If I put:

 

' or 1=1;drop table users; --

 

into txtUsername.  I not only bypass your login, I also might be able to alter tables in your schema.


My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#5 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts

Posted 03 September 2013 - 11:36 AM

If this is a project for school, leave the sql alone.  If this is for some kind of enterprise program, you better rethink that whole sql statement.

 

If I put:

 

' or 1=1;drop table users; --

 

into txtUsername.  I not only bypass your login, I also might be able to alter tables in your schema.

I am doing this in my free-time to help out a friend with something he is doing. The application in that case, will be an enterprise focused program so I thank you for adding the last bit about the security of the program


Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)

#6 tavichh

tavichh

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 399 posts

Posted 12 September 2013 - 08:38 PM   Best Answer

Nevermind I had a friend fix it for me. Thank you all for contributing to this thread!


Send a like my way if I helped you or if you found my post useful or even just enjoyed reading my post.
Thank you :)




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download