Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. public class SharedUtility
  2. {
  3. public static String Encrypt(string strData)
  4. {
  5. if (strData != "")
  6. {
  7. strData = string.Format("{0}|{1}", HttpContext.Current.Session.SessionID, strData);
  8. SHA1Managed shaM = new SHA1Managed();
  9. Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(strData)));
  10. Byte[] encByteData;
  11. encByteData = ASCIIEncoding.ASCII.GetBytes(strData);
  12. String encStrData = Convert.ToBase64String(encByteData);
  13. return encStrData;
  14. }
  15. else
  16. {
  17. return "";
  18. }
  19.  
  20. }
  21.  
  22. public static String Decrypt(string strData)
  23. {
  24. if (string.IsNullOrEmpty(strData) == false)
  25. {
  26. Byte[] decByteData;
  27. decByteData = Convert.FromBase64String(strData);
  28. String decStrData = ASCIIEncoding.ASCII.GetString(decByteData);
  29.  
  30. String[] SplitValue = decStrData.Split('|');
  31.  
  32. String ReturnValue = SplitValue[1];
  33. return ReturnValue;
  34. }
  35. else
  36. {
  37. return "";
  38. }
  39.  
  40. }
  41.  
  42. protected void btnSign_Click(object sender, EventArgs e)
  43. {
  44. try
  45. {
  46. string UserName = TextBoxUserName.Text.Trim().Replace("'", " ");
  47. string Password = SharedUtility.Encrypt(TextBoxPassword.Text.Trim().Replace("'", " "));
  48. string Result = WebUsers.AuthenticateUser(UserName, Password);
  49. if (Result.Contains("Success"))
  50. Response.Redirect("~/Home/home.aspx", false);
  51. else
  52. {
  53.  
  54. divResult.Visible = true;
  55. ResultLabel.Text = Result;
  56. ResultLabel.Visible = true;
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. ResultLabel.Text = ex.Message;
  62. }
  63. }
  64.  
  65.  
  66. }
  67.  
  68.  Invalid length for a Base-64 char array or string.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement