| @@ -147,12 +147,21 @@ | ||
| 147 | 147 | if ( $this->plugin->ban->is_ip_whitelisted( $ip ) ) { |
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | + // Calculate block time. | |
| 152 | + $minutes = (int) $this->get_option( 'patchstack_anti_bruteforce_minutes', 30 ); | |
| 153 | + $timeout = (int) $this->get_option( 'patchstack_anti_bruteforce_blocktime', 60 ); | |
| 154 | + if ( empty( $minutes ) || empty( $timeout ) ) { | |
| 155 | + $time = 30 + 60; | |
| 156 | + } else { | |
| 157 | + $time = $minutes + $timeout; | |
| 158 | + } | |
| 159 | + | |
| 151 | 160 | // Check if X failed login attempts were made. |
| 152 | 161 | global $wpdb; |
| 153 | 162 | $results = $wpdb->get_results( |
| 154 | - $wpdb->prepare( 'SELECT COUNT(*) AS numIps FROM ' . $wpdb->prefix . "patchstack_event_log WHERE ip = '%s' AND action = 'failed login' AND date >= ('" . current_time( 'mysql' ) . "' - INTERVAL %d MINUTE)", array( $ip, ( $this->get_option( 'patchstack_anti_bruteforce_blocktime', 60 ) + $this->get_option( 'patchstack_anti_bruteforce_minutes', 5 ) ) ) ), | |
| 163 | + $wpdb->prepare( 'SELECT COUNT(*) AS numIps FROM ' . $wpdb->prefix . "patchstack_event_log WHERE ip = '%s' AND action = 'failed login' AND date >= ('" . current_time( 'mysql' ) . "' - INTERVAL %d MINUTE)", array( $ip, $time ) ), | |
| 155 | 164 | OBJECT |
| 156 | 165 | ); |
| 157 | 166 | |
| 158 | 167 | // Determine the number of attempts. |