/// <summary> /// 验证是否有此Token /// </summary> /// <param name="token"></param> /// <returns></returns> static bool Validate(string token) { using (var helper = new DoRedisHash()) { return(helper.HashContainsEntry("Tokens", token)); } }
static bool IsAuth(string userId, string passWord) { using (var helper = new DoRedisHash()) { var p = helper.GetValueFromHash("user:"******"PassWord"); return(passWord == p); } }
/// <summary> /// 注册 /// </summary> /// <returns></returns> static bool Register(User user) { using (var helper = new DoRedisHash()) { helper.Core.SetRangeInHash("user:"******"Tokens", user.Token, user.ID); } return(true); }
public string SetHash(string hashId, string key, string value) { string result = "success"; try { DoRedisHash rh = new DoRedisHash(); rh.SetEntryInHash(hashId, key, value); } catch (Exception ex) { result = ex.Message; } return(result); }
/// <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); }
public string GetHash(string hashId) { string result = ""; try { DoRedisHash rh = new DoRedisHash(); var dic = rh.GetAllEntriesFromHash(hashId); if (dic != null) { result = Newtonsoft.Json.JsonConvert.SerializeObject(dic); } else { result = "无数据"; } } catch (Exception ex) { result = ex.Message; } return(result); }