internal static void RegisterIPFailureImp(Securable s, IPRegistered ipr) { ipr.Failures = ipr.Failures + 1; if (ipr.Failures >= s.AllowedIPFailures) { ipr.Allowed = false; ipr.DenialIssuedUntilTime = DateTime.Now.AddMinutes(s.IPFailureTimeDenying); } ipr.Update(); }
internal static void CheckIPImp(Securable s, IPRegistered ipr) { if (!ipr.Exists) { throw new UnauthorizedAccessException("IP has not been authenticated in any way"); } if (!ipr.Allowed && ipr.DenialIssuedUntilTime >= DateTime.Now) { throw new UnauthorizedAccessException("IP has been blocked until " + ipr.DenialIssuedUntilTime.ToString() + " (Server time)"); } else if (!ipr.Allowed) { ipr.Allowed = true; ipr.Failures = 0; ipr.Update(); } else { ipr.DenialIssuedUntilTime = DateTime.Now; ipr.Update(); } // Very expensive /*if (!ipr.SessionsRegisteredOnIP.Count >= s.SessionsPerIPAllowed) { // Check how many are valid (also clean up the expired ones) throw new UnauthorizedAccessException("Too many sessions"); }*/ }