Ejemplo n.º 1
0
 public bool Allow(string code, string workgroup, string command, IPAddress IPaddress)
 {
     if (tokens.ContainsKey(code) == true)
     {
         tokenInfo info = tokens[code];
         if (info.Expires <= helpers.UnixTimeNow())
         {
             PurgeExpired();
             return(false);
         }
         if (IPaddress.Equals(info.IP) == true)
         {
             return(true);
         }
     }
     if (OneTimeTokens.Contains(code) == true)
     {
         OneTimeTokens.Remove(code);
         return(true);
     }
     return(ScopeAllow(code, workgroup, command));
 }
Ejemplo n.º 2
0
 public string CreateToken(IPAddress IP)
 {
     if (IP != null)
     {
         PurgeExpired();
         bool   used = true;
         string last = "";
         while (used == true)
         {
             last = helpers.GetSHA1(last + helpers.UnixTimeNow() + new Random().Next(13256).ToString()).Substring(0, 10);
             used = tokens.ContainsKey(last);
             if (used == false)
             {
                 tokenInfo Info = new tokenInfo();
                 Info.IP      = IP;
                 Info.Expires = helpers.UnixTimeNow() + (60 * 10);
                 tokens.Add(last, Info);
                 break;
             }
         }
         return(last);
     }
     return(null);
 }