Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- using System.Security.Cryptography;
- using System.Text;
- using Styx;
- using TuanHACR.Share;
- namespace TuanHACR.Login
- {
- public partial class LoginCheck
- {
- public static string TimeStampCode;
- public static int FailLoginAttempt;
- public static DateTime FailLoginNextTime;
- public static bool CustomerMode = false;
- public static bool GuestMode = false;
- public const string KeyWord = " Legion welcome ";
- public static string Msp
- {
- get
- {
- switch (Func.ClassAtLoad)
- {
- case WoWClass.None:
- return "unknown";
- case WoWClass.Warrior:
- return "W";
- case WoWClass.Paladin:
- return "P";
- case WoWClass.Hunter:
- return "H";
- case WoWClass.Rogue:
- return "R";
- case WoWClass.Priest:
- return "I";
- case WoWClass.DeathKnight:
- return "D";
- case WoWClass.Shaman:
- return "S";
- case WoWClass.Mage:
- return "unknown";
- case WoWClass.Warlock:
- return "unknown";
- case WoWClass.Monk:
- return "M";
- case WoWClass.Druid:
- return "U";
- case WoWClass.DemonHunter:
- return "E";
- default:
- return "unknown";
- }
- }
- }
- // This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
- // This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
- // 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
- //private const string InitVector = "HR$2pIjHR$2pIj12";
- private const string InitVector = "tuanh3407@gmail.";
- // This constant is used to determine the keysize of the encryption algorithm.
- private const int Keysize = 256;
- internal static string Encrypt(string plainText, string passPhrase)
- {
- byte[] initVectorBytes = Encoding.UTF8.GetBytes(InitVector);
- byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
- PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null);
- byte[] keyBytes = password.GetBytes(Keysize/8);
- RijndaelManaged symmetricKey = new RijndaelManaged();
- symmetricKey.Mode = CipherMode.CBC;
- ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes);
- MemoryStream memoryStream = new MemoryStream();
- CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
- cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
- cryptoStream.FlushFinalBlock();
- byte[] cipherTextBytes = memoryStream.ToArray();
- memoryStream.Close();
- cryptoStream.Close();
- return Convert.ToBase64String(cipherTextBytes);
- }
- internal static string Decrypt(string cipherText, string passPhrase)
- {
- byte[] initVectorBytes = Encoding.ASCII.GetBytes(InitVector);
- byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
- PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null);
- byte[] keyBytes = password.GetBytes(Keysize/8);
- RijndaelManaged symmetricKey = new RijndaelManaged();
- symmetricKey.Mode = CipherMode.CBC;
- ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);
- MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
- CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
- byte[] plainTextBytes = new byte[cipherTextBytes.Length];
- int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
- memoryStream.Close();
- cryptoStream.Close();
- return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
- }
- internal static string CreateMD5Hash(string input)
- {
- byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes(input);
- byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
- string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
- return hashedString;
- }
- public static void LoginCheckTest()
- {
- var LoginCheckStart = DateTime.Now;
- string usernameText = "";
- string passwordText = "";
- TimeStampCode =
- ((Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
- var url =
- string.Format(
- "http://www.tuanha.biz/index.php?option=com_bookpro&controller=customer&task=bpajaxlogin_md5&username={0}&password={1}&msp={2}&md5={3}&rdc={4}",
- Func.Base64Encode(usernameText),
- Func.Base64Encode(passwordText),
- Msp,
- CreateMD5Hash(usernameText + Msp + TimeStampCode),
- 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);
- var tempString =
- (content.Replace(CreateMD5Hash(usernameText + KeyWord + TimeStampCode), ""));
- Log.Debug("tempString: {0}", tempString);
- if (tempString == content)
- {
- return;
- }
- tempString = Func.Base64Decode(tempString);
- Log.Debug("tempString Base64Decode: {0}", tempString);
- tempString = tempString.Substring(0, 10);
- Log.Debug("tempString Substring: {0}", tempString);
- var timeinReturnUrl = Convert.ToInt32(tempString);
- Log.Debug("timeinReturnUrl: {0}", timeinReturnUrl);
- var greater = (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - (60*15);
- Log.Debug("greater: {0}", greater);
- var lower = (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + (60*15);
- Log.Debug("lower: {0}", lower);
- var nowtoInt = (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - (60*15);
- Log.Debug("nowtoInt: {0}", nowtoInt);
- var hashExpected = CreateMD5Hash(usernameText + KeyWord + TimeStampCode);
- Log.Debug("hashExpected: {0}", hashExpected);
- Log.Debug("LoginCheck: {0} - {1}", content.Contains(hashExpected),
- (DateTime.Now - LoginCheckStart).TotalMilliseconds);
- }
- }
- }
Add Comment
Please, Sign In to add comment