Guest User

Untitled

a guest
Dec 3rd, 2016
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using Styx;
  7. using TuanHACR.Share;
  8.  
  9. namespace TuanHACR.Login
  10. {
  11. public partial class LoginCheck
  12. {
  13. public static string TimeStampCode;
  14. public static int FailLoginAttempt;
  15. public static DateTime FailLoginNextTime;
  16. public static bool CustomerMode = false;
  17. public static bool GuestMode = false;
  18. public const string KeyWord = " Legion welcome ";
  19.  
  20. public static string Msp
  21. {
  22. get
  23. {
  24. switch (Func.ClassAtLoad)
  25. {
  26. case WoWClass.None:
  27. return "unknown";
  28. case WoWClass.Warrior:
  29. return "W";
  30. case WoWClass.Paladin:
  31. return "P";
  32. case WoWClass.Hunter:
  33. return "H";
  34. case WoWClass.Rogue:
  35. return "R";
  36. case WoWClass.Priest:
  37. return "I";
  38. case WoWClass.DeathKnight:
  39. return "D";
  40. case WoWClass.Shaman:
  41. return "S";
  42. case WoWClass.Mage:
  43. return "unknown";
  44. case WoWClass.Warlock:
  45. return "unknown";
  46. case WoWClass.Monk:
  47. return "M";
  48. case WoWClass.Druid:
  49. return "U";
  50. case WoWClass.DemonHunter:
  51. return "E";
  52. default:
  53. return "unknown";
  54. }
  55. }
  56. }
  57.  
  58. // This constant string is used as a "salt" value for the PasswordDeriveBytes function calls.
  59. // This size of the IV (in bytes) must = (keysize / 8). Default keysize is 256, so the IV must be
  60. // 32 bytes long. Using a 16 character string here gives us 32 bytes when converted to a byte array.
  61. //private const string InitVector = "HR$2pIjHR$2pIj12";
  62. private const string InitVector = "tuanh3407@gmail.";
  63.  
  64. // This constant is used to determine the keysize of the encryption algorithm.
  65. private const int Keysize = 256;
  66.  
  67. internal static string Encrypt(string plainText, string passPhrase)
  68. {
  69. byte[] initVectorBytes = Encoding.UTF8.GetBytes(InitVector);
  70. byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
  71. PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null);
  72. byte[] keyBytes = password.GetBytes(Keysize/8);
  73. RijndaelManaged symmetricKey = new RijndaelManaged();
  74. symmetricKey.Mode = CipherMode.CBC;
  75. ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes);
  76. MemoryStream memoryStream = new MemoryStream();
  77. CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);
  78. cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
  79. cryptoStream.FlushFinalBlock();
  80. byte[] cipherTextBytes = memoryStream.ToArray();
  81. memoryStream.Close();
  82. cryptoStream.Close();
  83. return Convert.ToBase64String(cipherTextBytes);
  84. }
  85.  
  86. internal static string Decrypt(string cipherText, string passPhrase)
  87. {
  88. byte[] initVectorBytes = Encoding.ASCII.GetBytes(InitVector);
  89. byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
  90. PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, null);
  91. byte[] keyBytes = password.GetBytes(Keysize/8);
  92. RijndaelManaged symmetricKey = new RijndaelManaged();
  93. symmetricKey.Mode = CipherMode.CBC;
  94. ICryptoTransform decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);
  95. MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
  96. CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
  97. byte[] plainTextBytes = new byte[cipherTextBytes.Length];
  98. int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
  99. memoryStream.Close();
  100. cryptoStream.Close();
  101. return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
  102. }
  103.  
  104. internal static string CreateMD5Hash(string input)
  105. {
  106. byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes(input);
  107. byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
  108. string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
  109. return hashedString;
  110. }
  111.  
  112. public static void LoginCheckTest()
  113. {
  114. var LoginCheckStart = DateTime.Now;
  115.  
  116. string usernameText = "";
  117. string passwordText = "";
  118. TimeStampCode =
  119. ((Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
  120.  
  121. var url =
  122. string.Format(
  123. "http://www.tuanha.biz/index.php?option=com_bookpro&controller=customer&task=bpajaxlogin_md5&username={0}&password={1}&msp={2}&md5={3}&rdc={4}",
  124. Func.Base64Encode(usernameText),
  125. Func.Base64Encode(passwordText),
  126. Msp,
  127. CreateMD5Hash(usernameText + Msp + TimeStampCode),
  128. TimeStampCode);
  129.  
  130. Log.Debug("url: {0}", url);
  131.  
  132. var http = (HttpWebRequest) WebRequest.Create(url);
  133. var response = http.GetResponse();
  134. var stream = response.GetResponseStream();
  135. var sr = new StreamReader(stream);
  136. var content = sr.ReadToEnd();
  137. //Removing " character
  138. content = content.Replace("\"", "");
  139.  
  140. Log.Debug("content: {0}", content);
  141.  
  142. var tempString =
  143. (content.Replace(CreateMD5Hash(usernameText + KeyWord + TimeStampCode), ""));
  144. Log.Debug("tempString: {0}", tempString);
  145.  
  146. if (tempString == content)
  147. {
  148. return;
  149. }
  150.  
  151. tempString = Func.Base64Decode(tempString);
  152. Log.Debug("tempString Base64Decode: {0}", tempString);
  153.  
  154. tempString = tempString.Substring(0, 10);
  155. Log.Debug("tempString Substring: {0}", tempString);
  156.  
  157. var timeinReturnUrl = Convert.ToInt32(tempString);
  158. Log.Debug("timeinReturnUrl: {0}", timeinReturnUrl);
  159.  
  160. var greater = (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - (60*15);
  161. Log.Debug("greater: {0}", greater);
  162.  
  163. var lower = (Int32) (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds + (60*15);
  164. Log.Debug("lower: {0}", lower);
  165.  
  166. var nowtoInt = (DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds - (60*15);
  167. Log.Debug("nowtoInt: {0}", nowtoInt);
  168.  
  169. var hashExpected = CreateMD5Hash(usernameText + KeyWord + TimeStampCode);
  170. Log.Debug("hashExpected: {0}", hashExpected);
  171.  
  172. Log.Debug("LoginCheck: {0} - {1}", content.Contains(hashExpected),
  173. (DateTime.Now - LoginCheckStart).TotalMilliseconds);
  174. }
  175. }
  176. }
Add Comment
Please, Sign In to add comment