Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.30 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Net;
  5. using System.Windows.Forms;
  6. using Styx;
  7. using TuanHACR.Share;
  8.  
  9. namespace TuanHACR.Login
  10. {
  11. public partial class Login : Form
  12. {
  13. public Login()
  14. {
  15. InitializeComponent();
  16. }
  17.  
  18. private void THLogin_Load(object sender, EventArgs e)
  19. {
  20. AutoLogin.Checked = LoginSettings.Instance.AutoLogin;
  21. RememberMe.Checked = LoginSettings.Instance.RememberMe;
  22. ShowPassword.Checked = LoginSettings.Instance.ShowPassword;
  23.  
  24. if (LoginSettings.Instance.RememberMe)
  25. {
  26. if (LoginSettings.Instance.Username != "")
  27. {
  28. UsernametextBox.Text = LoginCheck.Decrypt(LoginSettings.Instance.Username, StyxWoW.Me.Name);
  29. }
  30. if (LoginSettings.Instance.Password != "")
  31. {
  32. PasswordtextBox.Text = LoginCheck.Decrypt(LoginSettings.Instance.Password, StyxWoW.Me.Name);
  33. }
  34. AutoLogin.Enabled = true;
  35. }
  36. else
  37. {
  38. AutoLogin.Enabled = false;
  39. }
  40.  
  41. if (LoginSettings.Instance.ShowPassword)
  42. {
  43. PasswordtextBox.UseSystemPasswordChar = false;
  44. }
  45. else
  46. {
  47. PasswordtextBox.UseSystemPasswordChar = true;
  48. }
  49.  
  50. _loginStartTime = DateTime.Now;
  51. var loginTimer = new Timer();
  52. loginTimer.Interval = 1000;
  53. loginTimer.Tick += new EventHandler(MyTimer_Tick);
  54. loginTimer.Tick += new EventHandler(GuestModeMyTimer_Tick);
  55. loginTimer.Start();
  56.  
  57. if (AutoLogin.Checked
  58. && UsernametextBox.Text.Length > 0
  59. && PasswordtextBox.Text.Length > 0)
  60. {
  61. LoginButton_Click(null, null);
  62. }
  63. }
  64.  
  65. private void LoginButton_Click(object sender, EventArgs e)
  66. {
  67. LoginCheck.CustomerMode = false;
  68.  
  69. var usernameText = UsernametextBox.Text.Trim();
  70. //UsernameText = HttpUtility.UrlEncode(UsernameText);
  71.  
  72. var passwordText = PasswordtextBox.Text.Trim();
  73. //PasswordText = HttpUtility.UrlEncode(PasswordText);
  74. LoginCheck.TimeStampCode =
  75. ((Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
  76.  
  77. if (usernameText.Length < 1
  78. || passwordText.Length < 1)
  79. {
  80. MessageBox.Show("Invalid Username or Password.", "Important Note", MessageBoxButtons.OK,
  81. MessageBoxIcon.Exclamation);
  82.  
  83. if (LoginSettings.Instance.AutoLogin)
  84. {
  85. LoginSettings.Instance.AutoLogin = false;
  86. }
  87. return;
  88. }
  89.  
  90. var url =
  91. string.Format(
  92. "http://www.tuanha.biz/index.php?option=com_bookpro&controller=customer&task=bpajaxlogin_md5_new&username={0}&password={1}&msp={2}&md5={3}&rdc={4}",
  93. Func.Base64Encode(usernameText),
  94. Func.Base64Encode(passwordText),
  95. LoginCheck.Msp,
  96. LoginCheck.CreateMD5Hash(usernameText + LoginCheck.Msp + LoginCheck.TimeStampCode),
  97. LoginCheck.TimeStampCode);
  98.  
  99. //Log.Debug("url: {0}", url);
  100.  
  101. var http = (HttpWebRequest) WebRequest.Create(url);
  102. var response = http.GetResponse();
  103. var stream = response.GetResponseStream();
  104. var sr = new StreamReader(stream);
  105. var content = sr.ReadToEnd();
  106. //Removing " character
  107. content = content.Replace("\"", "");
  108.  
  109. //Log.Debug("content: {0}", content);
  110.  
  111.  
  112. if (!content.Contains(LoginCheck.CreateMD5Hash(usernameText
  113. + LoginCheck.KeyWord
  114. + LoginCheck.TimeStampCode)))
  115. {
  116. //Log.Debug("!content.Contains: {0}", LoginCheck.CreateMD5Hash(usernameText
  117. // + LoginCheck.KeyWord
  118. // + LoginCheck.TimeStampCode));
  119.  
  120. LoginCheck.FailLoginAttempt = LoginCheck.FailLoginAttempt + 1;
  121. LoginCheck.CustomerMode = false;
  122. Log.Yellow("Invalid Username or Password. ({0})", LoginCheck.FailLoginAttempt);
  123. Log.Yellow("nMake sure you have purchased " + Func.CombatRoutineName +
  124. " and use login info for tuanha.biz");
  125.  
  126. if (LoginCheck.FailLoginAttempt > 5)
  127. {
  128. LoginCheck.FailLoginNextTime = DateTime.Now +
  129. TimeSpan.FromSeconds((LoginCheck.FailLoginAttempt - 10)*2);
  130. var nextlogintext = "Invalid Username or Password. ("
  131. + LoginCheck.FailLoginAttempt
  132. + ")\nMake sure you have purchased " + Func.CombatRoutineName
  133. + " and use login info for tuanha.biz"
  134. + "\nClick Forgot Login Info? to reset your password.";
  135. MessageBox.Show(nextlogintext, "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  136. }
  137. else
  138. {
  139. MessageBox.Show(
  140. "Invalid Username or Password. \nMake sure you have purchased "
  141. + Func.CombatRoutineName
  142. + " and use login info for tuanha.biz",
  143. "Important Note", MessageBoxButtons.OK,
  144. MessageBoxIcon.Exclamation);
  145. }
  146. return;
  147. }
  148.  
  149. //Log.Yellow("TempString:" + content);
  150. var tempString =
  151. (content.Replace(
  152. LoginCheck.CreateMD5Hash(usernameText
  153. + LoginCheck.KeyWord
  154. + LoginCheck.TimeStampCode), ""));
  155.  
  156. //Log.Yellow("TempString after removing MD5:" + TempString);
  157.  
  158. tempString = Func.Base64Decode(tempString);
  159. //Log.Yellow("TempString after Base64Decode:" + TempString);
  160.  
  161. tempString = tempString.Substring(0, 10);
  162. //Log.Yellow("TempString after Substring:" + TempString);
  163.  
  164. var timeinReturnUrl = Convert.ToInt32(tempString);
  165.  
  166.  
  167. if (content.Contains(LoginCheck.CreateMD5Hash(usernameText
  168. + LoginCheck.KeyWord
  169. + LoginCheck.TimeStampCode))
  170. && timeinReturnUrl >= (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - (60*15)
  171. && timeinReturnUrl < (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + (60*15)
  172. )
  173. {
  174. //Log.Debug("content.Contains: {0}", LoginCheck.CreateMD5Hash(usernameText
  175. // + LoginCheck.KeyWord
  176. // + LoginCheck.TimeStampCode));
  177.  
  178. LoginCheck.FailLoginAttempt = 0;
  179. LoginCheck.CustomerMode = true;
  180. LoginCheck.GuestMode = false;
  181. _loginStartTime = DateTime.Now - LoginTimeout;
  182.  
  183. Log.Yellow(Func.DashLine);
  184. //Log.Yellow("Thank you for" +
  185. // " supporting TuanHA Combat Routine.");
  186. Log.Yellow(Func.DashLine);
  187. //Log.Yellow(
  188. // "Please be advised that account sharing may result in access to the Combat Routine being blocked.");
  189. Log.Yellow(LoginCheck.Encrypt(usernameText, "123456"));
  190. Log.Yellow("Login Success...");
  191. Log.Yellow(Func.DashLine);
  192.  
  193.  
  194. if (!RememberMe.Checked)
  195. {
  196. LoginSettings.Instance.Username = "";
  197. LoginSettings.Instance.Password = "";
  198. }
  199.  
  200. LoginSettings.Instance.Username = LoginCheck.Encrypt(usernameText, StyxWoW.Me.Name);
  201. LoginSettings.Instance.Password = LoginCheck.Encrypt(passwordText, StyxWoW.Me.Name);
  202.  
  203. LoginSettings.Instance.Save();
  204.  
  205. Close();
  206. }
  207. else
  208. {
  209. //Log.Debug("content.Contains but fail: {0}", LoginCheck.CreateMD5Hash(usernameText
  210. // + LoginCheck.KeyWord
  211. // + LoginCheck.TimeStampCode));
  212.  
  213. LoginCheck.FailLoginAttempt = LoginCheck.FailLoginAttempt + 1;
  214. LoginCheck.CustomerMode = false;
  215. LoginCheck.GuestMode = true;
  216. Log.Yellow("Invalid Username or Password. ({0})", LoginCheck.FailLoginAttempt);
  217. Log.Yellow("Make sure you have purchased "
  218. + Func.CombatRoutineName
  219. + " and use login info for tuanha.biz");
  220.  
  221. if (LoginCheck.FailLoginAttempt > 5)
  222. {
  223. LoginCheck.FailLoginNextTime = DateTime.Now +
  224. TimeSpan.FromSeconds((LoginCheck.FailLoginAttempt - 10)*2);
  225. var nextlogintext = "Invalid Username or Password. ("
  226. + LoginCheck.FailLoginAttempt
  227. + ")\nMake sure you have purchased "
  228. + Func.CombatRoutineName
  229. + " and use login info for tuanha.biz"
  230. + "\nClick Forgot Login Info? to reset your password.";
  231. MessageBox.Show(nextlogintext, "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  232. }
  233. else
  234. {
  235. MessageBox.Show(
  236. "Invalid Username or Password. "
  237. + "\nMake sure you have purchased"
  238. + Func.CombatRoutineName
  239. + " and use login info for tuanha.biz",
  240. "Important Note", MessageBoxButtons.OK,
  241. MessageBoxIcon.Exclamation);
  242. }
  243. }
  244. }
  245.  
  246. private void MyTimer_Tick(object sender, EventArgs e)
  247. {
  248. if (LoginCheck.FailLoginNextTime <= DateTime.Now)
  249. {
  250. if (LoginButton.Enabled == false)
  251. {
  252. LoginButton.Enabled = true;
  253. }
  254. return;
  255. }
  256.  
  257. if (LoginButton.Enabled)
  258. {
  259. LoginButton.Enabled = false;
  260. }
  261. }
  262.  
  263. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  264. {
  265. Process.Start("http://www.tuanha.biz/index.php?option=com_bookpro&view=login");
  266. }
  267.  
  268. private void RememberMe_CheckedChanged(object sender, EventArgs e)
  269. {
  270. LoginSettings.Instance.RememberMe = RememberMe.Checked;
  271.  
  272. if (RememberMe.Checked)
  273. {
  274. AutoLogin.Enabled = true;
  275. }
  276. else
  277. {
  278. AutoLogin.Enabled = false;
  279. }
  280. }
  281.  
  282. private void ShowPassword_CheckedChanged(object sender, EventArgs e)
  283. {
  284. LoginSettings.Instance.ShowPassword = ShowPassword.Checked;
  285.  
  286. if (ShowPassword.Checked)
  287. {
  288. PasswordtextBox.UseSystemPasswordChar = false;
  289. }
  290. else
  291. {
  292. PasswordtextBox.UseSystemPasswordChar = true;
  293. }
  294. }
  295.  
  296. private void PressEnter_KeyDown(object sender, KeyEventArgs e)
  297. {
  298. if (e.KeyCode == Keys.Enter
  299. && LoginCheck.FailLoginNextTime <= DateTime.Now)
  300. {
  301. LoginButton_Click(null, null);
  302. }
  303. }
  304.  
  305. private void UsernametextBoxSelectAll(object sender, EventArgs e)
  306. {
  307. UsernametextBox.SelectAll();
  308. }
  309.  
  310. private void PasswordtextBoxSelectAll(object sender, EventArgs e)
  311. {
  312. PasswordtextBox.SelectAll();
  313. }
  314.  
  315. private void AutoLogin_CheckedChanged(object sender, EventArgs e)
  316. {
  317. LoginSettings.Instance.AutoLogin = AutoLogin.Checked;
  318. }
  319.  
  320. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  321. {
  322. }
  323.  
  324. private void GuestLoginButton_Click(object sender, EventArgs e)
  325. {
  326. LoginCheck.GuestMode = true;
  327. _loginStartTime = DateTime.Now - LoginTimeout;
  328. Close();
  329. }
  330.  
  331. #region Timer
  332.  
  333. private static readonly TimeSpan LoginTimeout = TimeSpan.FromSeconds(30);
  334. private static DateTime _loginStartTime;
  335.  
  336. private void GuestModeMyTimer_Tick(object sender, EventArgs e)
  337. {
  338. var runningSeconds = Math.Round((_loginStartTime + LoginTimeout - DateTime.Now).TotalSeconds);
  339.  
  340. if (runningSeconds > 0)
  341. {
  342. Log.Yellow("Auto Login as GuestMode Mode in {0} seconds", runningSeconds);
  343. GuestLoginButton.Text = "GuestMode Mode (" + runningSeconds + ")";
  344. }
  345. else
  346. {
  347. GuestLoginButton_Click(null, null);
  348. }
  349. }
  350.  
  351. #endregion
  352.  
  353. private void GuestReadButton_Click(object sender, EventArgs e)
  354. {
  355. Process.Start("http://www.tuanha.biz/index.php?option=com_content&view=article&id=275&Itemid=257");
  356. }
  357. }
  358. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement