Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- using System.Windows.Forms;
- using Styx;
- using TuanHACR.Share;
- namespace TuanHACR.Login
- {
- public partial class Login : Form
- {
- public Login()
- {
- InitializeComponent();
- }
- private void THLogin_Load(object sender, EventArgs e)
- {
- AutoLogin.Checked = LoginSettings.Instance.AutoLogin;
- RememberMe.Checked = LoginSettings.Instance.RememberMe;
- ShowPassword.Checked = LoginSettings.Instance.ShowPassword;
- if (LoginSettings.Instance.RememberMe)
- {
- if (LoginSettings.Instance.Username != "")
- {
- UsernametextBox.Text = LoginCheck.Decrypt(LoginSettings.Instance.Username, StyxWoW.Me.Name);
- }
- if (LoginSettings.Instance.Password != "")
- {
- PasswordtextBox.Text = LoginCheck.Decrypt(LoginSettings.Instance.Password, StyxWoW.Me.Name);
- }
- AutoLogin.Enabled = true;
- }
- else
- {
- AutoLogin.Enabled = false;
- }
- if (LoginSettings.Instance.ShowPassword)
- {
- PasswordtextBox.UseSystemPasswordChar = false;
- }
- else
- {
- PasswordtextBox.UseSystemPasswordChar = true;
- }
- _loginStartTime = DateTime.Now;
- var loginTimer = new Timer();
- loginTimer.Interval = 1000;
- loginTimer.Tick += new EventHandler(MyTimer_Tick);
- loginTimer.Tick += new EventHandler(GuestModeMyTimer_Tick);
- loginTimer.Start();
- if (AutoLogin.Checked
- && UsernametextBox.Text.Length > 0
- && PasswordtextBox.Text.Length > 0)
- {
- LoginButton_Click(null, null);
- }
- }
- private void LoginButton_Click(object sender, EventArgs e)
- {
- LoginCheck.CustomerMode = false;
- var usernameText = UsernametextBox.Text.Trim();
- //UsernameText = HttpUtility.UrlEncode(UsernameText);
- var passwordText = PasswordtextBox.Text.Trim();
- //PasswordText = HttpUtility.UrlEncode(PasswordText);
- LoginCheck.TimeStampCode =
- ((Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
- if (usernameText.Length < 1
- || passwordText.Length < 1)
- {
- MessageBox.Show("Invalid Username or Password.", "Important Note", MessageBoxButtons.OK,
- MessageBoxIcon.Exclamation);
- if (LoginSettings.Instance.AutoLogin)
- {
- LoginSettings.Instance.AutoLogin = false;
- }
- return;
- }
- var url =
- string.Format(
- "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}",
- Func.Base64Encode(usernameText),
- Func.Base64Encode(passwordText),
- LoginCheck.Msp,
- LoginCheck.CreateMD5Hash(usernameText + LoginCheck.Msp + LoginCheck.TimeStampCode),
- LoginCheck.TimeStampCode);
- //Log.Debug("url: {0}", url);
- var http = (HttpWebRequest) WebRequest.Create(url);
- var response = http.GetResponse();
- var stream = response.GetResponseStream();
- var sr = new StreamReader(stream);
- var content = sr.ReadToEnd();
- //Removing " character
- content = content.Replace("\"", "");
- //Log.Debug("content: {0}", content);
- if (!content.Contains(LoginCheck.CreateMD5Hash(usernameText
- + LoginCheck.KeyWord
- + LoginCheck.TimeStampCode)))
- {
- //Log.Debug("!content.Contains: {0}", LoginCheck.CreateMD5Hash(usernameText
- // + LoginCheck.KeyWord
- // + LoginCheck.TimeStampCode));
- LoginCheck.FailLoginAttempt = LoginCheck.FailLoginAttempt + 1;
- LoginCheck.CustomerMode = false;
- Log.Yellow("Invalid Username or Password. ({0})", LoginCheck.FailLoginAttempt);
- Log.Yellow("nMake sure you have purchased " + Func.CombatRoutineName +
- " and use login info for tuanha.biz");
- if (LoginCheck.FailLoginAttempt > 5)
- {
- LoginCheck.FailLoginNextTime = DateTime.Now +
- TimeSpan.FromSeconds((LoginCheck.FailLoginAttempt - 10)*2);
- var nextlogintext = "Invalid Username or Password. ("
- + LoginCheck.FailLoginAttempt
- + ")\nMake sure you have purchased " + Func.CombatRoutineName
- + " and use login info for tuanha.biz"
- + "\nClick Forgot Login Info? to reset your password.";
- MessageBox.Show(nextlogintext, "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- else
- {
- MessageBox.Show(
- "Invalid Username or Password. \nMake sure you have purchased "
- + Func.CombatRoutineName
- + " and use login info for tuanha.biz",
- "Important Note", MessageBoxButtons.OK,
- MessageBoxIcon.Exclamation);
- }
- return;
- }
- //Log.Yellow("TempString:" + content);
- var tempString =
- (content.Replace(
- LoginCheck.CreateMD5Hash(usernameText
- + LoginCheck.KeyWord
- + LoginCheck.TimeStampCode), ""));
- //Log.Yellow("TempString after removing MD5:" + TempString);
- tempString = Func.Base64Decode(tempString);
- //Log.Yellow("TempString after Base64Decode:" + TempString);
- tempString = tempString.Substring(0, 10);
- //Log.Yellow("TempString after Substring:" + TempString);
- var timeinReturnUrl = Convert.ToInt32(tempString);
- if (content.Contains(LoginCheck.CreateMD5Hash(usernameText
- + LoginCheck.KeyWord
- + LoginCheck.TimeStampCode))
- && timeinReturnUrl >= (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - (60*15)
- && timeinReturnUrl < (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + (60*15)
- )
- {
- //Log.Debug("content.Contains: {0}", LoginCheck.CreateMD5Hash(usernameText
- // + LoginCheck.KeyWord
- // + LoginCheck.TimeStampCode));
- LoginCheck.FailLoginAttempt = 0;
- LoginCheck.CustomerMode = true;
- LoginCheck.GuestMode = false;
- _loginStartTime = DateTime.Now - LoginTimeout;
- Log.Yellow(Func.DashLine);
- //Log.Yellow("Thank you for" +
- // " supporting TuanHA Combat Routine.");
- Log.Yellow(Func.DashLine);
- //Log.Yellow(
- // "Please be advised that account sharing may result in access to the Combat Routine being blocked.");
- Log.Yellow(LoginCheck.Encrypt(usernameText, "123456"));
- Log.Yellow("Login Success...");
- Log.Yellow(Func.DashLine);
- if (!RememberMe.Checked)
- {
- LoginSettings.Instance.Username = "";
- LoginSettings.Instance.Password = "";
- }
- LoginSettings.Instance.Username = LoginCheck.Encrypt(usernameText, StyxWoW.Me.Name);
- LoginSettings.Instance.Password = LoginCheck.Encrypt(passwordText, StyxWoW.Me.Name);
- LoginSettings.Instance.Save();
- Close();
- }
- else
- {
- //Log.Debug("content.Contains but fail: {0}", LoginCheck.CreateMD5Hash(usernameText
- // + LoginCheck.KeyWord
- // + LoginCheck.TimeStampCode));
- LoginCheck.FailLoginAttempt = LoginCheck.FailLoginAttempt + 1;
- LoginCheck.CustomerMode = false;
- LoginCheck.GuestMode = true;
- Log.Yellow("Invalid Username or Password. ({0})", LoginCheck.FailLoginAttempt);
- Log.Yellow("Make sure you have purchased "
- + Func.CombatRoutineName
- + " and use login info for tuanha.biz");
- if (LoginCheck.FailLoginAttempt > 5)
- {
- LoginCheck.FailLoginNextTime = DateTime.Now +
- TimeSpan.FromSeconds((LoginCheck.FailLoginAttempt - 10)*2);
- var nextlogintext = "Invalid Username or Password. ("
- + LoginCheck.FailLoginAttempt
- + ")\nMake sure you have purchased "
- + Func.CombatRoutineName
- + " and use login info for tuanha.biz"
- + "\nClick Forgot Login Info? to reset your password.";
- MessageBox.Show(nextlogintext, "Important Note", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- else
- {
- MessageBox.Show(
- "Invalid Username or Password. "
- + "\nMake sure you have purchased"
- + Func.CombatRoutineName
- + " and use login info for tuanha.biz",
- "Important Note", MessageBoxButtons.OK,
- MessageBoxIcon.Exclamation);
- }
- }
- }
- private void MyTimer_Tick(object sender, EventArgs e)
- {
- if (LoginCheck.FailLoginNextTime <= DateTime.Now)
- {
- if (LoginButton.Enabled == false)
- {
- LoginButton.Enabled = true;
- }
- return;
- }
- if (LoginButton.Enabled)
- {
- LoginButton.Enabled = false;
- }
- }
- private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- Process.Start("http://www.tuanha.biz/index.php?option=com_bookpro&view=login");
- }
- private void RememberMe_CheckedChanged(object sender, EventArgs e)
- {
- LoginSettings.Instance.RememberMe = RememberMe.Checked;
- if (RememberMe.Checked)
- {
- AutoLogin.Enabled = true;
- }
- else
- {
- AutoLogin.Enabled = false;
- }
- }
- private void ShowPassword_CheckedChanged(object sender, EventArgs e)
- {
- LoginSettings.Instance.ShowPassword = ShowPassword.Checked;
- if (ShowPassword.Checked)
- {
- PasswordtextBox.UseSystemPasswordChar = false;
- }
- else
- {
- PasswordtextBox.UseSystemPasswordChar = true;
- }
- }
- private void PressEnter_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter
- && LoginCheck.FailLoginNextTime <= DateTime.Now)
- {
- LoginButton_Click(null, null);
- }
- }
- private void UsernametextBoxSelectAll(object sender, EventArgs e)
- {
- UsernametextBox.SelectAll();
- }
- private void PasswordtextBoxSelectAll(object sender, EventArgs e)
- {
- PasswordtextBox.SelectAll();
- }
- private void AutoLogin_CheckedChanged(object sender, EventArgs e)
- {
- LoginSettings.Instance.AutoLogin = AutoLogin.Checked;
- }
- private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
- {
- }
- private void GuestLoginButton_Click(object sender, EventArgs e)
- {
- LoginCheck.GuestMode = true;
- _loginStartTime = DateTime.Now - LoginTimeout;
- Close();
- }
- #region Timer
- private static readonly TimeSpan LoginTimeout = TimeSpan.FromSeconds(30);
- private static DateTime _loginStartTime;
- private void GuestModeMyTimer_Tick(object sender, EventArgs e)
- {
- var runningSeconds = Math.Round((_loginStartTime + LoginTimeout - DateTime.Now).TotalSeconds);
- if (runningSeconds > 0)
- {
- Log.Yellow("Auto Login as GuestMode Mode in {0} seconds", runningSeconds);
- GuestLoginButton.Text = "GuestMode Mode (" + runningSeconds + ")";
- }
- else
- {
- GuestLoginButton_Click(null, null);
- }
- }
- #endregion
- private void GuestReadButton_Click(object sender, EventArgs e)
- {
- Process.Start("http://www.tuanha.biz/index.php?option=com_content&view=article&id=275&Itemid=257");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement