Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5. using System.Net;
  6. using System.IO;
  7. using System.Windows.Forms;
  8.  
  9. namespace Hawt35.Tools
  10. {
  11. public class AccountCheck
  12. {
  13. public static bool CheckAccount(string URL, string username, string password, out string message)
  14. {
  15. string Sha1Pass = CalculateSHA1(password, Encoding.ASCII).ToLower();
  16. message = "";
  17. string request = String.Format("{0}?username={1}&password={2}",URL, username, Sha1Pass);
  18. try
  19. {
  20. //MessageBox.Show("URL :"+URL+"\r\n Username : "+username+"\r\nPassword Sha1 : "+Sha1Pass+"\r\n Full Message reuturn : "+request);
  21. string lol = GetString(request);
  22. bool success = (lol.Substring(0, 1) == "1") ? true : false;
  23. if(!success) message = lol.Substring(2, lol.Length - 2);
  24. return success;
  25. }
  26. catch (WebException ex)
  27. {
  28. throw ex;
  29. }
  30. }
  31.  
  32. /// <summary>
  33. /// Calculates SHA1 hash
  34. /// </summary>
  35. /// <param name="text">input string</param>
  36. /// <param name="enc">Character encoding</param>
  37. /// <returns>SHA1 hash</returns>
  38. private static string CalculateSHA1(string text, Encoding enc)
  39. {
  40. byte[] buffer = enc.GetBytes(text);
  41. SHA1CryptoServiceProvider cryptoTransformSHA1 =
  42. new SHA1CryptoServiceProvider();
  43. string hash = BitConverter.ToString(
  44. cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
  45.  
  46. return hash;
  47. }
  48.  
  49. private static string GetString(string URL)
  50. {
  51. WebRequest request = (WebRequest)
  52. WebRequest.Create(URL);
  53.  
  54. request.Proxy = null;
  55.  
  56. WebResponse myResponse = request.GetResponse();
  57. StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.ASCII);
  58. string result = sr.ReadToEnd();
  59. sr.Close();
  60. myResponse.Close();
  61. return result;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement