コード例 #1
0
        public static SecurityData GetSecurityData(string securityKey)
        {
            if (string.IsNullOrWhiteSpace(securityKey))
            {
                return(null);
            }
            securityKey = Uri.UnescapeDataString(securityKey);
            string userInfo = SecurityUtility.DecryptSecurityKey(securityKey);

            string[] arr = userInfo.Split('#');

            SecurityData data = null;

            if (userInfo != null && arr.Length >= 4)
            {
                data = new SecurityData();
                DateTime expiration = DateTime.MinValue; int userId = 0; bool remember = false;
                int.TryParse(arr[0], out userId);
                DateTime.TryParse(arr[1], out expiration);
                bool.TryParse(arr[3], out remember);
                data.UserID     = userId;
                data.Expiration = expiration;
                data.UserData   = SecurityUtility.DecryptUserData(Uri.UnescapeDataString(arr[2]));
                data.Remember   = remember;
                data.UserPhone  = arr.Length >= 5 ? arr[4] : "";
                data.UserName   = arr.Length >= 6 ? arr[5] : "";
            }
            return(data);
        }
コード例 #2
0
        public static string GetSecurityKey(SecurityData data)
        {
            string userdata = Uri.EscapeDataString(SecurityUtility.EncryptUserData(data.UserData));
            string input    = string.Format("{0}#{1}#{2}#{3}#{4}#{5}", data.UserID, data.Expiration, userdata, data.Remember, data.UserPhone, data.UserName);
            string key      = SecurityUtility.EncryptSecurityKey(input);

            //base on http://blogs.msdn.com/b/yangxind/archive/2006/11/09/don-t-use-net-system-uri-unescapedatastring-in-url-decoding.aspx
            return(Uri.EscapeDataString(key));
        }
コード例 #3
0
 public static string RefeshSecurityKey(SecurityData securityData)
 {
     securityData.Expiration = SecurityUtility.GetExpiration(securityData.Remember);
     return(SecurityUtility.GetSecurityKey(securityData));
 }