How to generate a username automatically in a Drupal site with the Automatic User Names module?

Nov 18, 2020
Generates a username automatically in Drupal site

First of all, generating a username automatically in your Drupal site is very useful for the site admins and website visitors.

Let's start with the fact that today, to use the services of the site, users have to log in.

As a rule, registration includes filling in the following data:

  • first/last name
  • Username
  • login

The Automatic User Names module removes the required username field when registering on the site. Where can it come in handy? Any business that has a website where users should register can use this module.  

For example, in online store sites where the username is optional, the Automatic User Names module will generate a unique name for each user (like an ID).

To find out all the advantages of the Automatic User Names module and how it can be beneficial for your business, our web support agency has created this blog. Below, we will show you how to set up a module for a random username generator.

How does the Automatic User Names module work on the Drupal site?

Let's go straight to a real-world example of how Automatic User Names works.

The module allows you to remove the required field "Username" when registering on the site.

Simply put, this module saves time for your website visitors, because it automatically generates a username for them.

Mandatory modules for the smooth operation of the Automatic User Names module:

  • token

Additional modules (not installed with the auto_username module):

  • logintobogan
  • realname

It is often used with other modules such as:

  • Auto user names are extended to LoginToboggan
  • Real Name is often used in Auto usernames to use the real first and last name.

How to install and configure the Automatic User Names module on a Drupal site:

To enter the Automatic User Names module settings, you need to go to the following address 

"lirup.loc / admin/config/people/accounts/patterns"

1. You can set a pattern (template) for the "Username" field on the settings page. That is, the "Username" field is automatically replaced according to the entered pattern you establish.

2. In the field "Replacement pattern" you can see the list of available tokens the pattern works with. 

Replacement pattern

For example, in the field "Pattern for user name" the default token is "[user: mail]" - the email address of the user account. It can be replaced, for example, with "[user: url]" - the URL of the account profile page.

3. There are additional settings, such as:

  • updating the username every time the profile is updated
  • character separates words in headers (separator)
  • change of register
  • the maximum length of the alias
  • maximum text length of any component in the username
  • filter username with letters and numbers only according to ASCII-96
  • replace all spaces in the separator
  • words that will be removed from the username, for example, profanity
other settings automatic user name

4. The punctuation marks section allows you to choose three options for each punctuation mark.

These include options to:

  • delete
  • replace separator
  • no action (do not change)
punctuation marks section

5. The setting of the punctuation section

Setting of the punctuation section

For comparison, we will show you what the Username looks like when the module is running and when it is not activated.

Registration form (module is enabled)

The "Username" field is missing because the module automatically generates a username.

module automatically generates a username



Registration form (module is disabled)

The "Username" field is present because the module is disabled. Information in this field will be recorded as the username.

Registration form (module is disabled)


username module is disabled

Generates a username automatically in your Drupal site with the Automatic User Names module!

Generating a username automatically is a handy thing that makes life easier for your site visitors and increases user satisfaction.

If you are looking to generate a username automatically on the Drupal site, this module is perfect for the job.

In general, the settings for this module are not very heavy. However, you can always hire web developers to extend the functionality of your Drupal site in a matter of hours.

 Get new blog posts by email