I'm working on a Community Website and 99% of the time a new user has an unique username. But for my requirement, it is required to allow duplicate usernames.

Is there a way to change drupal default behavior from unique username+email+pass to unique email+pass?

  • 4
    I dont think its even logical, i am sorry. – niksmac May 18 '13 at 6:33
  • 2
    @NikhilM Not sure why it isn't logical. The SE sites allow duplicate nicknames. – mpdonadio May 18 '13 at 14:44
  • 2
    Is the requirement for non-unique username or non-unique screennames? – mpdonadio May 18 '13 at 14:44
  • @MPD Second comment makes sense :) – niksmac May 19 '13 at 7:07
  • As long as every UN is associated with a unique id it definitely should be possible to allow duplicate usernames, shouldn't it? – leymannx Jun 14 '13 at 15:38

There is no setting or existing module that will do this for you. I do not think it is a good idea to let two users share the same username, because there is so much in Drupal that depends on usernames being unique, and this will break if you make two usernames identical.

You do not tell us why you want to have this feature. However, if you are content with letting users authenticate using their email address (which is guaranteed to be unique), rather than their username, the Email registration module may solve your problem.

However, the Email registration module does not let the user pick his or her own username, but generates an unique username based upon the email address. I want my users to pick their own username, so I use a variant of Email registration that does this. It is named RealnameReg. It is a sandbox, but since it is based on Email registration it is stable. I am using it myself on several production sites.

| improve this answer | |
  • As long as every user has a uid why should duplicate usernames be a problem??? – leymannx Jun 14 '13 at 15:34

Usenames cannot be duplicate. Alternatively you can use Email Registration module if you want login based on email and password.

Allow users to register and login using only an email address. Users can then log-in using their email address and password for authentication.

Also have a look on LoginToboggan module

The LoginToboggan module offers several modifications of the Drupal login system in an external module by offering the following features and usability improvements:

| improve this answer | |

I think @GisleHannemyr has a good solution, but I am going to throw out an alternate.

If you look at user_schema() you will see that the name column on {users} is a unique key. So, to have duplicate username, a solution would have to alter the schema and remove this index. While I can't say this for certain, I am pretty sure Bad Things would happen if you do this.

My suggestion would be to work within the unique username requirement, but field out the user entity (admin/config/people/accounts/fields) and add a screen name. Then you can implement hook_username_alter() to use this field instead of $account->name.

| improve this answer | |
  • Few points: - Login system will be broken and you have to alter the form_state and resolve the email to an actual username. - user_load function will need many changes. – AyeshK May 18 '13 at 15:20
  • @AyeshK Confused. I have done this with a lot of sites. This only changes the display of the name, not what the user logs in with. – mpdonadio May 18 '13 at 16:55
  • 1
    How did you allow users to login ? If there are dupe usernames allowed, you would would expect "MPD" to be unique, so does someone else. – AyeshK May 19 '13 at 1:21
  • @AyeshK That's why this solution doesn't change the username. You login with the unique username, but everywhere on the frontend that format_username() is used, the hook uses the $user->field_screename instead of $user->name. – mpdonadio May 19 '13 at 11:32

Username needs to be unique - Drupal needs to know who to log in. Having that said, you can separate login user name from display user name. Simply add non-unique "display name" text field, and in templates use it instead of built-in username.

| improve this answer | |

I think ultimately what you want is the Email Registration module, as mentioned in several of the other answers. However, you can allow users to create their own display names by using the Real Name module. This will allow several users to choose the same screenname to be displayed throughout the site. The actual username will be automatically generated by the Email Registration module, but never displayed (this module will also ensure that the underlying usernames are unique). The Real Name module will handle displaying the user's chosen screenname (which can be anything the user chooses).

After installing and enabling both modules, you'll need to add a "Username" text field to the user accounts (on the page admin/config/people/accounts/fields). Then use the token for that field in the Real Name configuration (page admin/config/people/realname). The token will look something like [user:field-username] (the token browser should help you find the correct token).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.