| @@ -161,9 +161,9 @@ | ||
| 161 | 161 | * |
| 162 | 162 | * @param string $username The username used in the failed login attempt. |
| 163 | 163 | */ |
| 164 | 164 | public function process_fail_attempt_compatibility( $username ) { |
| 165 | - if ( empty( $username ) ) { | |
| 165 | + if ( ! is_string( $username ) || '' === $username ) { | |
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | if ( in_array( $username, $this->model->get_blacklisted_username(), true ) ) { |
| @@ -204,9 +204,9 @@ | ||
| 204 | 204 | * @param string $username The username used in the failed login attempt. |
| 205 | 205 | * @param WP_Error $error The error object associated with the login failure. |
| 206 | 206 | */ |
| 207 | 207 | public function process_fail_attempt( $username, $error ) { |
| 208 | - if ( empty( $username ) ) { | |
| 208 | + if ( ! is_string( $username ) || '' === $username ) { | |
| 209 | 209 | return; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | foreach ( $this->ip as $ip ) { |
| @@ -344,23 +344,9 @@ | ||
| 344 | 344 | * @param string $scenario The scenario constant (e.g., SCENARIO_LOGIN_FAIL). |
| 345 | 345 | * @param string $message Additional message for the log. |
| 346 | 346 | */ |
| 347 | 347 | public function log_event( $ip, $username, $scenario, $message = '' ) { |
| 348 | - $user_agent = defender_get_data_from_request( 'HTTP_USER_AGENT', 's' ); | |
| 349 | - $model = new Lockout_Log(); | |
| 350 | - $model->ip = $ip; | |
| 351 | - $model->user_agent = isset( $user_agent ) | |
| 352 | - ? User_Agent::fast_cleaning( $user_agent ) | |
| 353 | - : null; | |
| 354 | - $model->date = time(); | |
| 355 | - $model->tried = $username; | |
| 356 | - $model->blog_id = get_current_blog_id(); | |
| 357 | - | |
| 358 | - $ip_to_country = $this->ip_to_country( $ip ); | |
| 359 | - | |
| 360 | - if ( isset( $ip_to_country['iso'] ) ) { | |
| 361 | - $model->country_iso_code = $ip_to_country['iso']; | |
| 362 | - } | |
| 348 | + $model = Lockout_Log::create( $ip, $username ); | |
| 363 | 349 | |
| 364 | 350 | switch ( $scenario ) { |
| 365 | 351 | case self::SCENARIO_LOGIN_FAIL: |
| 366 | 352 | $model->type = Lockout_Log::AUTH_FAIL; |