Using your email address as your Drupal username

It can be difficult to remember all of the usernames and passwords that you use to log in to various websites across the internet, so why force users to create a new username for your web site? It's easier on everyone to simply combine the username and email address fields. It also cleans up your registration form a bit.

In Drupal, there are two modules that can help you to accomplish this:

These two modules are mutually exclusive— they are not compatible with each other, so you'll have to pick one. I prefer to use Email Registration, and I'll explain why.

Email Registration

Email Registration simplifies the user registration form by removing the 'username' field. By default, the module will automatically generate a username for a new user based upon the first part (before the @) of his/her email address. For example, if I registered for a new account with email address [email protected], I would end up with username madmatter23.

That's great, but it's not exactly what I'd like. I'd like my username to be my full email address. Luckily, Email Registration provides a hook_email_registration_name() to let you customize exactly how the username will be generated. I used the hook in this way:

/* 
 * Implements hook_email_registration_name().
 */
function grasmash_email_registration_name($edit, $account) {
  return $account->mail;
}

Adding a similar snippet to your own custom module will give you complete control. That's all there is to it!

LoginToboggan

This module still forces users to choose their own username during registration. However, after they're registered, it will allow them to login using either their username or their email address. Hence my preference for Email Registration.

LoginToboggan also has a number of other nice features, such as redirecting users after registration or login, and providing a login form on the 403 Access Denied page. If you really need one of these features, there are a number of alternative modules that provide the same functionality:

Final Thought

Using this method does have at least one major drawback: you no longer have the option to display a user's username while preserving the privacy of their email address. However, this problem can easily be circumvented by simply using an optional 'alias' field, or by utilizing a programmatically applied handle for users based on other field values.

Drupal Version Compatibility:

Comments

Thanks for sharing.
However, It did not work for me for D7.
I have created an issue here: http://drupal.org/node/1389080.

Perry.

Try these steps:

  1. Clear your caches after adding the hook.
  2. Add the hook to a custom module rather than to your template.php file.

Let me know if that works!

Nice description of the available options.

I'd encourage anyone interested in seeing this functionality in Core to visit http://drupal.org/node/111317 where there is a patch needing review.

The patch allows admins of Drupal 8.x sites to choose how users can log in (email only, username only, email or username).

Thanks.

My solution in the past has been to use LoginToboggan to allow e-mail logins, then use String Override to rename the "Username" field to "Full Name". As Drupal supports spaces in usernames, a name like "Gareth Price" is valid and can be safely displayed to the public.

What do you do when the second John Smith tries to register on the site?

The email registration module will ensure that user account names are kept unique by applying an integer to the end of the user name string.

Yeah.I can not agree with you anymore. I thank you for sitting down imparting your musings and thoughts to a considerable measure of bookworms over there. http://www.mmoxe.com/FFXI/

The vast majority of sites I've worked on have fallen under the category of no need for a username.

No one wants to remember a username, when you can just use your email and a password.

BTW: There is also Shared Email if you like to allow people to create multiple accounts (not be stopped by re-using an email for sales lead reasons).

i was looking for auto generation of a "random name" 'or "number" (not UID)and assign it to user during registration or after registration (like Avtar) , my intention is to protect identity of the user when user is participating in discussion forums or groups.By no means user should be able to disclose the identity, if i allow user to create user name almost 50% of users will choose a name will choose with their first name or lat name or name resembling to either of them, i want to prevent that.

Thank you for the informative review! I've also decided to go with Email Registration.

The separate username field should really be optional in Drupal core.

thanks for sharing this,it helps me a lot

I was able to use these modules together. First enable LoginToboggan and configure how you like, EXCEPT you need to Disable using the e-mail address on the login screen. After that, you can enable Email Registration. It worked great for me.

Using email registration + code snippet above, it's possible to create users with illegal user names. When this user is updated, an error is reported.

email registration + code snipped above + pathauto can take care of puncuations as @ and . at admin/config/search/path/settings.

DogeHilerNero <a href="http://vikaswieier.com">xaikalitag</a> greefulse http://usillumaror.com - iziananatt shertyIrrargy http://gussannghor.com Playclaro

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.