public override void Validate(string userName, string password) { if (null == userName || null == password) { throw new ArgumentNullException(); } var r = new Sider.RedisClient<string>(); var keys = r.Keys("*"); if (keys.Contains(userName)) { var stp = Stopwatch.StartNew(); var pass = r.Get(userName); stp.Stop(); Debug.WriteLine(stp.ElapsedMilliseconds + " ms for redis key"); if (pass != password) { throw new FaultException("Token is not valid!"); } } else { throw new FaultException("There is no session!"); } //if (!(userName == "mucit" && password == "pass") && !(userName == "test2" && password == "2tset")) //{ // // This throws an informative fault to the client. // throw new FaultException("Unknown Username or Incorrect Password"); // // When you do not want to throw an infomative fault to the client, // // throw the following exception. // // throw new SecurityTokenException("Unknown Username or Incorrect Password"); //} }
public void Benchmark_SET_raw_bytes_1k_Sider() { // Create Redis Wrapper var redis = new Sider.RedisClient(); Run("Sider 1K", 1000, (i, bytes) => redis.SetRaw("eitan" + i.ToString(), bytes)); }
public string CreateToken(string userName, string password) { if (userName == "mucit" && password == "pass") { var guid = Guid.NewGuid().ToString(); Sider.RedisClient<string> c = new Sider.RedisClient<string>(); c.Set(userName, guid); //TokenDictionary["mucit"] = guid; return guid; } return string.Empty; }
public override void Validate(string userName, string sessionId) { if (HttpContext.Current.Request.Path.Contains("AuthService.svc")) { HttpContext.Current.Items["AppId"] = userName; return; } if (null == userName || null == sessionId) { throw new ArgumentNullException(); } var r = new Sider.RedisClient<SessionRegistry>(); var keys = r.Keys("*"); if (keys.Contains(sessionId)) { var stp = Stopwatch.StartNew(); var session = r.Get(sessionId); stp.Stop(); Debug.WriteLine(stp.ElapsedMilliseconds + " ms for redis key"); if (session.AppId != userName) { throw new FaultException("Token is not valid!"); } HttpContext.Current.Items["AppId"] = session.AppId; HttpContext.Current.Items["UserId"] = session.UserId; //HttpContext.Current.Items["password"] = password; } else { throw new FaultException("There is no session!"); } //if (!(userName == "mucit" && password == "pass") && !(userName == "test2" && password == "2tset")) //{ // // This throws an informative fault to the client. // throw new FaultException("Unknown Username or Incorrect Password"); // // When you do not want to throw an infomative fault to the client, // // throw the following exception. // // throw new SecurityTokenException("Unknown Username or Incorrect Password"); //} }