Beispiel #1
0
 public static bool TryParse(string encryptedAuthKey, out AuthKey key)
 {
     try
     {
         if (!String.IsNullOrEmpty(encryptedAuthKey))
         {
             string value = Cryptography.Decrypt(encryptedAuthKey.Replace(' ', '+'), SecurityManager.EncryptKey, SecurityManager.EncryptIV, EncryptionAlgorithm.Rijndael);
             if (!String.IsNullOrEmpty(value))
             {
                 string[] parts = value.Split('|');
                 if (parts != null && parts.Length >= 3)
                 {
                     key             = new AuthKey(parts[0], parts[1].Split(','));
                     key.DateCreated = new DateTime(Convert.ToInt32(parts[2]));
                     if (parts.Length > 3)
                     {
                         for (int i = 2; i < parts.Length; i++)
                         {
                             key.Args.Add(parts[i]);
                         }
                     }
                     return(true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Log.Write(ex.ToString(), true);
     }
     key = AuthKey.Empty;
     return(false);
 }
 public static User GetUser(AuthKey key)
 {
     if (key != AuthKey.Empty)
     {
         MembershipUser user = Membership.GetUser(key.UserName);
         if (user != null && user is User)
         {
             // Ensure that the supplied key matches the encryption value for this user.
             AuthKey checkKey = new AuthKey(user.UserName, Roles.GetRolesForUser(user.UserName));
             if (checkKey.ToString().Equals(key.ToString()))
             {
                 return(user as User);
             }
         }
     }
     return(null);
 }