Advertisement
Guest User

log

a guest
Aug 25th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5.  
  6.  
  7. string MyConnection = "datasource=localhost;port=3306;username=root;password=password";
  8. MySqlConnection MyConn = new MySqlConnection(MyConnection);
  9. MySqlCommand MyCommand = new MySqlCommand("select * from bans.toollogin where user_name='" + this.UserTextBox.Text + "' and password='" + this.PassTextBox.Text + "' ;", MyConn);
  10. MySqlDataReader MyReader;
  11.  
  12.  
  13. MyConn.Open();
  14. MyReader = MyCommand.ExecuteReader();
  15. int count = 0;
  16. while (MyReader.Read())
  17. {
  18. Console.WriteLine(MyReader[count]);
  19. count++;
  20. }
  21. if (count == 1)
  22. {
  23. MessageBox.Show("Username and password is correct");
  24. this.Hide();
  25. Form2 f2 = new Form2();
  26. f2.ShowDialog();
  27. }
  28. else if (count > 1)
  29. {
  30.  
  31. MessageBox.Show("Duplicate Username and passwor.\nAccess denied.");
  32. }
  33. else
  34.  
  35. {
  36. MessageBox.Show("Username and password is incorrect.\nPleas try again.");
  37. }
  38. MyConn.Close();
  39.  
  40. }
  41. catch (Exception ex)
  42. {
  43.  
  44. MessageBox.Show(ex.Message);
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement