Esempio n. 1
0
        /// <summary>
        /// 判断UserID和Token是否匹配,进而判断用户是否合法
        /// </summary>
        /// <returns></returns>
        public bool IsValid(bool needAdmin = false)
        {
            var aes = new FzLib.Cryptography.Aes();

            aes.SetStringKey(Key + UserID);
            aes.SetStringIV("");
            try
            {
                string[] items = aes.Decrypt(Token).Split("-");
                if (items[0] != UserID.ToString())
                {
                    return(false);
                }
                if (needAdmin && !bool.Parse(items[1]))
                {
                    return(false);
                }
                //预留过期检测
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取Token
        /// </summary>
        /// <returns></returns>
        public string GetToken()
        {
            var aes = new FzLib.Cryptography.Aes();

            aes.SetStringKey(Key + UserID);
            aes.SetStringIV("");
            return(aes.Encrypt(string.Join("-", UserID.ToString(), DateTime.Now.ToString("yyyyMMdd"))));
        }