Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public bool tryLogin(string username, string password)
  2. {
  3. MySqlConnection con = new MySqlConnection("host=hostremoved;user=user_removed;password=passwordremoved;database=databaseremoved;");
  4. MySqlCommand cmd = new MySqlCommand("SELECT * FROM login WHERE user_name = '" + username + "' AND user_pass = '" + password + "';");
  5. cmd.Connection = con;
  6. con.Open();
  7. MySqlDataReader reader = cmd.ExecuteReader();
  8. if (reader.Read() != false)
  9. {
  10.  
  11. if (reader.IsDBNull(0) == true)
  12. {
  13. cmd.Connection.Close();
  14. reader.Dispose();
  15. cmd.Dispose();
  16. return false;
  17. }
  18. else
  19. {
  20. cmd.Connection.Close();
  21. reader.Dispose();
  22. cmd.Dispose();
  23. return true;
  24. }
  25. }
  26. else
  27. {
  28. return false;
  29. }
  30. }
  31.  
  32. private void btnlogin_Click(object sender, EventArgs e)
  33. {
  34. if (tryLogin(txtuser.Text, txtpass.Text) == true)
  35. {
  36. MessageBox.Show("Login worked!");
  37. }
  38. else
  39. {
  40. MessageBox.Show("Login failed!");
  41.  
  42. GRANT ALL ON yourDbName.* TO 'yourUser'@'yourIP' IDENTIFIED BY "yourPassword";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement