Sholo.Web.Security/Authentication/User/UserAuthentication.cs
/// <summary>
/// Calculates the hash of the FormsAuthenticationTicket's properties 
/// concatenated together with the salt.  This is used as a first line of 
/// defense against ticket tampering to potentially avoid an unnecessary read
/// from the Provider.
/// </summary>
/// <param name="formsAuthenticationTicket">the formsAuthenticationTicket to 
/// compute the hash of</param>
/// <returns>the hash of ticket's properties</returns>
Calculates the hash of the FormsAuthenticationTicket's properties
concatenated together with the salt.  This is used as a first line of
defense against ticket tampering to potentially avoid an unnecessary read
from the Provider.
Calculates the hash of the FormsAuthenticationTicket ' s properties concatenated together with the salt . This is used as a first line of defense against ticket tampering to potentially avoid an unnecessary read from the Provider .
public static string CalculateFormsAuthTicketHash(FormsAuthenticationTicket formsAuthenticationTicket)
        {
            if (formsAuthenticationTicket == null)
            {
                throw new ArgumentNullException("formsAuthenticationTicket", "The formsAuthenticationTicket parameter is required.");
            }
            Initialize();
            string input = string.Format(
                "||{0}|{1}|{2}|{3}|{4}|{5}|{6}||",
                formsAuthenticationTicket.CookiePath,
                formsAuthenticationTicket.Expiration,
                formsAuthenticationTicket.IsPersistent,
                formsAuthenticationTicket.IssueDate,
                formsAuthenticationTicket.Name,
                formsAuthenticationTicket.Version,
                HashSalt
            );
            byte[] inputBytes = Encoding.UTF32.GetBytes(input);
            byte[] hashBytes = HashAlgorithm.ComputeHash(inputBytes);
            StringBuilder sb = new StringBuilder();
            if (hashBytes.Length != HashAlgorithmByteLength)
            {
                throw new InvalidOperationException("Unable to compute hash of formsAuthenticationTicket.");
            }
            for (int i = 0; i < hashBytes.Length; i++)
            {
                sb.Append(hashBytes[i].ToString("x2"));
            }
            if (sb.Length != HashAlgorithmStringLength)
            {
                throw new InvalidOperationException("Unable to compute hash of formsAuthenticationTicket");
            }
            string hash = sb.ToString();
            return hash;
        }
public static string CalculateFormsAuthTicketHash ( FormsAuthenticationTicket formsAuthenticationTicket ) { if ( formsAuthenticationTicket == null ) { throw new ArgumentNullException ( " " , " " ) ; } Initialize ( ) ; string input = string . Format ( " " , formsAuthenticationTicket . CookiePath , formsAuthenticationTicket . Expiration , formsAuthenticationTicket . IsPersistent , formsAuthenticationTicket . IssueDate , formsAuthenticationTicket . Name , formsAuthenticationTicket . Version , HashSalt ) ; byte [ ] inputBytes = Encoding . UTF32 . GetBytes ( input ) ; byte [ ] hashBytes = HashAlgorithm . ComputeHash ( inputBytes ) ; StringBuilder sb = new StringBuilder ( ) ; if ( hashBytes . Length != HashAlgorithmByteLength ) { throw new InvalidOperationException ( " " ) ; } for ( int i = 0 ; i < hashBytes . Length ; i ++ ) { sb . Append ( hashBytes [ i ] . ToString ( " " ) ) ; } if ( sb . Length != HashAlgorithmStringLength ) { throw new InvalidOperationException ( " " ) ; } string hash = sb . ToString ( ) ; return hash ; }
Calculates the hash of the FormsAuthenticationTicket's properties
concatenated together with the salt.
Calculates the hash of the FormsAuthenticationTicket ' s properties concatenated together with the salt .
the hash of ticket's properties
the hash of ticket ' s properties
formsAuthenticationTicket
FormsAuthenticationTicket
the formsAuthenticationTicket to
compute the hash of
the formsAuthenticationTicket to compute the hash of