$ip, 'prefix' => $prefix, 'difficulty' => $difficulty, 'issued_at' => time(), ), self::TTL_SECONDS ); return array( 'challenge_id' => $challenge_id, 'prefix' => $prefix, 'difficulty' => $difficulty, ); } public static function verify( $challenge_id, $counter, $ip ) { $data = get_transient( self::TRANSIENT_PREFIX . $challenge_id ); if ( ! $data || $data['ip'] !== $ip ) { return false; } $hash = hash( 'sha256', $data['prefix'] . $counter ); $ok = 0 === strncmp( $hash, str_repeat( '0', $data['difficulty'] ), $data['difficulty'] ); if ( $ok ) { delete_transient( self::TRANSIENT_PREFIX . $challenge_id ); self::issue_pass_cookie( $ip ); } return $ok; } protected static function issue_pass_cookie( $ip ) { $token = wp_generate_password( 32, false ); set_transient( 'argus_wpd_pass_' . $token, $ip, self::PASS_TTL_SECONDS ); setcookie( self::COOKIE_NAME, $token, time() + self::PASS_TTL_SECONDS, COOKIEPATH ?: '/', COOKIE_DOMAIN, is_ssl(), true ); } public static function has_valid_pass( $ip ) { if ( empty( $_COOKIE[ self::COOKIE_NAME ] ) ) { // phpcs:ignore return false; } $token = sanitize_text_field( wp_unslash( $_COOKIE[ self::COOKIE_NAME ] ) ); // phpcs:ignore $stored_ip = get_transient( 'argus_wpd_pass_' . $token ); return $stored_ip && hash_equals( (string) $stored_ip, $ip ); } public static function render_and_exit( $ip ) { $challenge = self::issue( $ip ); nocache_headers(); status_header( 429 ); header( 'Content-Type: text/html; charset=utf-8' ); ?> Verifying your browser…

Verifying your browser

This site is protected by ARGUS WordPress Defence. This should only take a moment.