private IPAddressEntry ParseIPAddressEntry(SQLiteDataReader reader) { string ipAddress = reader.GetString(0); long lastFailedLogin = reader.GetInt64(1); long failedLoginCount = reader.GetInt64(2); object banDateObj = reader.GetValue(3); long banDateLong = (banDateObj == null || banDateObj == DBNull.Value ? 0 : Convert.ToInt64(banDateObj)); DateTime?banDate = (banDateLong == 0 ? (DateTime?)null : IPBanExtensionMethods.UnixTimeStampToDateTimeMilliseconds(banDateLong)); DateTime lastFailedLoginDt = IPBanExtensionMethods.UnixTimeStampToDateTimeMilliseconds(lastFailedLogin); return(new IPAddressEntry { IPAddress = ipAddress, LastFailedLogin = lastFailedLoginDt, FailedLoginCount = (int)failedLoginCount, BanDate = banDate }); }
/// <summary> /// Get the ban date for an ip address /// </summary> /// <param name="ipAddress">IP address</param> /// <returns>Ban date or null if not banned or not in the database</returns> public DateTime?GetBanDate(string ipAddress) { if (IPAddress.TryParse(ipAddress, out IPAddress ipAddressObj)) { byte[] ipBytes = ipAddressObj.GetAddressBytes(); using (SQLiteDataReader reader = ExecuteReader("SELECT BanDate FROM IPAddresses WHERE IPAddress = @Param0", ipBytes)) { if (reader.Read()) { object val = reader.GetValue(0); if (val != null && val != DBNull.Value) { return(IPBanExtensionMethods.UnixTimeStampToDateTimeMilliseconds((long)val)); } } } } return(null); }