Você está em boa companhia com suporte incrível 🤝

Limitar tentativas de login

Bloqueia o IP após 5 tentativas de login falhas por 1 hora, sem precisar de plugin.

Time Full Services Time Full Services
PHP
add_filter('authenticate', function ($user, $username, $password) {
  $ip      = $_SERVER['REMOTE_ADDR'];
  $key     = 'login_attempts_' . md5($ip);
  $attempts = (int) get_transient($key);

  if ($attempts >= 5) {
    return new WP_Error('too_many_attempts', 'Muitas tentativas. Tente novamente em 1 hora.');
  }

  if ($username && $password && is_wp_error($user)) {
    set_transient($key, $attempts + 1, HOUR_IN_SECONDS);
  }

  if (!is_wp_error($user)) {
    delete_transient($key);
  }

  return $user;
}, 30, 3);

Seja PRO.

Tenha acesso a snippets de código premium — PHP, JavaScript, CSS e HTML prontos para usar em seus projetos.

Conhecer o plano Pro →