WordPress:Usernameに特定の単語を含むユーザーのメンバー登録をブロックする

Last Updated: 2023 年 07 月 11 日 댓글

WordPressでは、会員登録機能を有効にして、訪問者の会員登録を許可することができます。 洗練されたメンバーシップサイトを運営したい場合は、Ultimate MemberやWP-Membersなどのメンバーシッププラグインを使用できます。 WooCommerceでメンバーシップ方式で商品やサービスを販売したい場合は、ダンビストアのサービス有料商品やYITHプラグインを利用できます(参照).

会員登録機能を有効にすると、訪問者が増え、ボットによるスパム加入者も増加します。 その場合、UMまたはWP-Membersプラグインを使用している場合は、reCAPTCHA機能を有効にしてスパムユーザーの登録をブロックできます(「Ultimate MemberおよびWP-MembersプラグインでreCAPTCHAを設定する注)メンバーシッププラグインがインストールされていない場合 キャプチャ 4WPのような無料のプラグインを使用することも可能です。

WordPress:Usernameに特定の単語を含むユーザーのメンバー登録をブロックする

WordPress:Usernameに特定の単語を含むユーザーのメンバー登録をブロックする

Naver カフェにIDにtestを含むユーザーが30日に40人(以降はXNUMX人)ほど加入しているという質問が最近登場したことがあります。

ボットなのか人なのか30日にXNUMX回加入をします。 昨日から。
IDはtest03493094です。
이멜주소가 test4029029@gmail.com304eoe.dfojeofj 대충 이런 식입니다.
発見直ちに削除するのに引き続き登録をします。 IDブロックまたはtest〜で始まるIDサブスクリプション自体をブロックできませんか?
攻撃に見えるのに… 難しいですね

出典: Naver カフェ

CAPTCHA 4WPプラグインをお勧めしますが、セッティングが間違っているのか、本来効果がないのかは分からなくても効果がないそうです。

これに関して、次のコードをテーマの関数ファイルに追加すると、ユーザー名(Username)に「test」を含むユーザーの購読がブロックされます。

/**
 * This WordPress filter prevents user registration if the username contains the word 'test'.
 * It checks the provided username during registration for the occurrence of 'test'.
 * If it finds 'test' in the username, it adds an error that is displayed to the user,
 * effectively blocking the registration process.
 */

add_filter( 'registration_errors', 'disable_user_registration_for_username', 10, 3 );
function disable_user_registration_for_username ( $errors, $sanitized_user_login, $user_email ) {
    // Check if username contains "test"
    if ( strpos( $sanitized_user_login, 'test' ) !== false ) {
        // Throw registration error
        $errors->add( 'username_error', '<strong>ERROR</strong>: The word "test" is not allowed in usernames.' );
    }

    return $errors;
}

実際にこのコードを追加した後、スパム加入者が消えたという。 チャイルドテーマを作成してチャイルドテーマ内の関数ファイルに追加しなければ、後でテーマを更新するとコードは消えません。

ユーザー名に test または user という単語を含む加入者の購読をブロックしたい場合は、次のように適用できます。

add_filter( 'registration_errors', 'disable_user_registration_for_username', 10, 3 );
function disable_user_registration_for_username ( $errors, $sanitized_user_login, $user_email ) {
    // Check if username contains "test" or "user"
    if ( stripos( $sanitized_user_login, 'test' ) !== false || stripos( $sanitized_user_login, 'user' ) !== false ) {
        // Throw registration error
        $errors->add( 'username_error', '<strong>ERROR</strong>: The words "test" or "user" are not allowed in usernames.' );
    }

    return $errors;
}

上記のコードに対してセキュリティ上安全であるか チャットGPTに聞いてみるとセキュリティの観点から比較的安全だそうです。 上記のコードにセキュリティ上の問題がある場合は、コメントでお知らせいただきありがとうございます。

The provided code is relatively safe from a security standpoint as it doesn't perform any unsafe operations such as executing raw user-provided data, writing data to the database without sanitization, or revealing sensitive information.

It simply checks the username during the registration process for a specific pattern, and if it finds it, it adds an error to the registration process, which prevents the form from being submitted.

参照

ワードクラッカーのアバター画像

ワードクラッカー

プロの英国翻訳家として活動しており、10年以上 WordPress 情報パッケージのブログを運営している。 Naver カフェ Admin

コメントを残す

コメント

カカオトーク相談 カトクサービス相談