Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public bool VerificaLogin()
  2. {
  3. bool result = false;
  4. string StringDeConexao = "SERVER = localhost; DATABASE = global; UID = root; PASSWORD=";
  5.  
  6. using (MySqlConnection cn = new MySqlConnection())
  7. {
  8. cn.ConnectionString = StringDeConexao;
  9.  
  10. try
  11. {
  12. MySqlCommand cmd = new MySqlCommand("SELECT * FROM usuarios WHERE login = '" + txtlogin.Text + "'AND senha = '" + GerarHashMd5(txtsenha.Text) + "';", cn);
  13. cn.Open();
  14. MySqlDataReader dados = cmd.ExecuteReader();
  15.  
  16. result = dados.HasRows;
  17. }
  18. catch (MySqlException e)
  19. {
  20. MetroFramework.MetroMessageBox.Show(this, "" + e.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  21. }
  22. finally
  23. {
  24. cn.Close();
  25. }
  26. }
  27. return result;
  28. }
  29.  
  30. public bool Logado = false;
  31.  
  32. private void btnentrar_Click(object sender, EventArgs e)
  33. {
  34. bool result = VerificaLogin();
  35.  
  36. Logado = result;
  37.  
  38. if (result)
  39. {
  40. MetroFramework.MetroMessageBox.Show(this, "Seja Bem-vindo", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  41. this.Close();
  42. }
  43. else
  44. {
  45. MetroFramework.MetroMessageBox.Show(this, "Usuário e/ou senha incorretos", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement