Advertisement
Laurcook

Untitled

May 8th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1.  
  2.  
  3. private void flatClose1_Click(object sender, EventArgs e)
  4. {
  5. Application.Exit();
  6. Environment.Exit(4);
  7. }
  8.  
  9. private void flatButton2_Click(object sender, EventArgs e)
  10. {
  11. if (!flatTextBox2.Text.Equals("") && !flatTextBox1.Text.Equals("")) ;
  12.  
  13.  
  14. StringBuilder sb = new StringBuilder();
  15. using (SHA256 hash = SHA256Managed.Create())
  16. {
  17. Encoding enc = Encoding.UTF8;
  18. Byte[] result = hash.ComputeHash(enc.GetBytes(flatTextBox2.Text));
  19.  
  20. foreach (Byte b in result)
  21. {
  22. sb.Append(b.ToString("x2"));
  23. }
  24.  
  25. }
  26.  
  27. string connectionstring = "datasource=127.0.0.1;port=3306;username=root;password=your_password;database=xproject ex;SslMode=none;";
  28. string query = "INSERT INTO users(ID,Username,Password) VALUES(null, '" + flatTextBox1.Text + "', " + sb.ToString() + "')";
  29. string query2 = "SELECT * FROM users WHERE username='" + flatTextBox1.Text + "' AND password='" + sb.ToString() + "'";
  30.  
  31. MySqlConnection databaseconnection = new MySqlConnection(connectionstring);
  32. MySqlCommand insertcommand = new MySqlCommand(query, databaseconnection);
  33. MySqlCommand Checkcommand = new MySqlCommand(query2, databaseconnection);
  34. insertcommand.CommandTimeout = 60;
  35. Checkcommand.CommandTimeout = 60;
  36. MySqlDataReader reader;
  37. try
  38. {
  39. databaseconnection.Open();
  40. reader = insertcommand.ExecuteReader();
  41. reader.Close();
  42. reader = Checkcommand.ExecuteReader();
  43.  
  44. if (reader.HasRows)
  45. {
  46. MessageBox.Show("You have been registered");
  47. }
  48. else
  49. {
  50. MessageBox.Show("Sql Code Error");
  51. }
  52. }
  53. catch (Exception ex)
  54. {
  55. MessageBox.Show(ex.ToString());
  56. }
  57.  
  58. }
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement