I want to prevent users from registering on my site if they enter a username from a given list.

In my rule I've entered the event as "After saving a new user account" and the condition as "text comparison" with the data selector "account:name".

Problem 1) I can't seem to enter a list of usernames in the "matching text - value" box, only one name at a time (surely I don't have to create multiple "or" conditions for each name in my list?)

Problem 2) The "comparison operation value" doesn't give the option "equals" so if I use "contains" this would block a legitimate username which is a string containing a banned username.

Problem 3) In my "actions" I have "display a message" and this works if the text comparison is true, so it seems my event and action are correct in principle. But I can't block the user - I have another action element "Block a user" with the Parameter: "User: [account]" but the user remains active. (Ideally the user wouldn't be blocked but rather the account would not actually be registered, and the user trying to register would just be sent back to the "register account" form to enter a different username.)

Is this doable with Rules or do I need a custom module?

Comments

jigish.addweb’s picture

You need to follow below steup.

1) You need to create your custom rule event with below code.

function MODULENAME_rules_event_info() {
  return array(
    'check_user_name_valid' => array(
      'label' => t('Your Event Name'),
      'module' => 'MODULENAME',
      'group' => 'Group name where this event will list in rule' ,
      )
    )
}        

Event : Your custom rule event name
Actions : Set message for banned username
Page redirect(on particular location)

2) Apply hook on user registration form and write a code for check banned username. If username is in list of banned username then call your event within your code.

<?php
                // YOUR CODE WILL COME HERE.
                // CALL YOUR RULE IF USER NAME IS IN LIST OF BANNED USER LIST.
                rules_invoke_event('sendemail_rule_event');
        ?>

Let me know in case of any query/concern regarding this.

Thanks!

TR’s picture

Status: Active » Fixed

#1 will work. Or you can use a regular expression to do the text comparison, or you can write your own Rules condition to use, or you can populate a list data variable with all your words then do a text comparison against the list in a loop.

Writing your own hook as in #1 will be the simplest and most efficient way of checking against an arbitrarily large list from an arbitrary source. Invoking your own custom event will give you a simple and flexible way to react when you encounter a username you want to ban.

TR’s picture

Status: Fixed » Closed (fixed)