Guest User

Untitled

a guest
Jun 16th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. private void loginButton_Click(object sender, EventArgs e)
  2. {
  3. username = usernameTextBox.Text;
  4. password = passwordTextBox.Text;
  5.  
  6. if (String.IsNullOrEmpty(username))
  7. {
  8. MessageBox.Show("Please input username!", "Warning!",
  9. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  10. return;
  11. }
  12.  
  13. if (String.IsNullOrEmpty(password))
  14. {
  15. MessageBox.Show("Please input password!", "Warning!",
  16. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  17. return;
  18. }
  19.  
  20. loginButton.Text = "Logging...";
  21.  
  22. string usernameResult = Database.access.GetColumnData(NCLib.ValueType.VALUETYPE_STRING, "accounts", "username", "username", username, true);
  23. string passwordResult = Database.access.GetColumnData(NCLib.ValueType.VALUETYPE_STRING, "accounts", "password", "password", Hash.SHA1(password), true);
  24. if (usernameResult != username)
  25. {
  26. MessageBox.Show("This account doesn't exist.", "Error!",
  27. MessageBoxButtons.OK, MessageBoxIcon.Error);
  28. loginButton.Text = "Login";
  29. return;
  30. }
  31.  
  32. if (usernameResult == username && passwordResult == Hash.SHA1(password))
  33. {
  34. string hwidInfo = HWID.getHWID().ToString().Replace(" ", "");
  35. string hwidResult = Database.access.GetColumnData(NCLib.ValueType.VALUETYPE_STRING, "accounts", "hwid", "username", username, true);
  36. string rankResult = Database.access.GetColumnData(NCLib.ValueType.VALUETYPE_INT32, "accounts", "rank", "username", username, true);
  37. if (hwidInfo != hwidResult && rankResult != "1" && rankResult != "3")
  38. {
  39. MessageBox.Show("Your HWID doesn't match. Your account has been locked. Ask for a reset.", "Error!",
  40. MessageBoxButtons.OK, MessageBoxIcon.Error);
  41. Database.access.Update("accounts", "rank", "1", "username", username);
  42. loginButton.Text = "Login";
  43. return;
  44. }
  45.  
  46. if (rankResult == "0")
  47. {
  48. MessageBox.Show("Your account is banned.", "Error!",
  49. MessageBoxButtons.OK, MessageBoxIcon.Error);
  50. loginButton.Text = "Login";
  51. return;
  52. }
  53. else if (rankResult == "1")
  54. {
  55. MessageBox.Show("Your account is locked due to HWID change.", "Error!",
  56. MessageBoxButtons.OK, MessageBoxIcon.Error);
  57. loginButton.Text = "Login";
  58. return;
  59. }
  60. else if (rankResult != "2" && rankResult != "3")
  61. {
  62. MessageBox.Show("Your rank isn't recognized.", "Error!",
  63. MessageBoxButtons.OK, MessageBoxIcon.Error);
  64. loginButton.Text = "Login";
  65. return;
  66. }
  67.  
  68. string[] logValues = { Convert.ToString(0), username, Functions.getIP(), DateTime.Now.ToString(), "Client login" };
  69. Database.access.Insert("logs", logValues);
  70.  
  71. Database.access.Update("accounts", "ip", Functions.getIP(), "username", username);
  72. Database.access.Update("accounts", "pcname", Functions.getPCName(), "username", username);
  73.  
  74. this.Hide();
  75. var result2 = new TestApp().ShowDialog();
  76.  
  77. if (result2 == DialogResult.Cancel)
  78. this.Close();
  79. }
  80. else
  81. {
  82. MessageBox.Show("The username or the password is wrong, please try again.", "Error!",
  83. MessageBoxButtons.OK, MessageBoxIcon.Error);
  84. }
  85.  
  86. loginButton.Text = "Login";
  87. }
Add Comment
Please, Sign In to add comment