Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SharedUtility
- {
- public static String Encrypt(string strData)
- {
- if (strData != "")
- {
- strData = string.Format("{0}|{1}", HttpContext.Current.Session.SessionID, strData);
- SHA1Managed shaM = new SHA1Managed();
- Convert.ToBase64String(shaM.ComputeHash(Encoding.ASCII.GetBytes(strData)));
- Byte[] encByteData;
- encByteData = ASCIIEncoding.ASCII.GetBytes(strData);
- String encStrData = Convert.ToBase64String(encByteData);
- return encStrData;
- }
- else
- {
- return "";
- }
- }
- public static String Decrypt(string strData)
- {
- if (string.IsNullOrEmpty(strData) == false)
- {
- Byte[] decByteData;
- decByteData = Convert.FromBase64String(strData);
- String decStrData = ASCIIEncoding.ASCII.GetString(decByteData);
- String[] SplitValue = decStrData.Split('|');
- String ReturnValue = SplitValue[1];
- return ReturnValue;
- }
- else
- {
- return "";
- }
- }
- protected void btnSign_Click(object sender, EventArgs e)
- {
- try
- {
- string UserName = TextBoxUserName.Text.Trim().Replace("'", " ");
- string Password = SharedUtility.Encrypt(TextBoxPassword.Text.Trim().Replace("'", " "));
- string Result = WebUsers.AuthenticateUser(UserName, Password);
- if (Result.Contains("Success"))
- Response.Redirect("~/Home/home.aspx", false);
- else
- {
- divResult.Visible = true;
- ResultLabel.Text = Result;
- ResultLabel.Visible = true;
- }
- }
- catch (Exception ex)
- {
- ResultLabel.Text = ex.Message;
- }
- }
- }
- Invalid length for a Base-64 char array or string.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement