Example #1
0
 static bool IsAuth(string userId, string passWord)
 {
     using (var helper = new DoRedisHash())
     {
         var p = helper.GetValueFromHash("user:"******"PassWord");
         return(passWord == p);
     }
 }
Example #2
0
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="passWord"></param>
        static string Login(string userId, string passWord)
        {
            if (IsAuth(userId, passWord))//验证密码是否正确
            {
                using (var helper = new DoRedisHash())
                {
                    //移除失效token
                    var token = helper.GetValueFromHash("user:"******"Token");
                    helper.RemoveEntryFromHash("Tokens", token);

                    token = Guid.NewGuid().ToString();
                    helper.SetEntryInHash("Tokens", token, userId);          //更新到tokens散列
                    helper.SetEntryInHash("user:"******"Token", token); //更新用户token
                    return(token);
                }
            }
            return(null);
        }