Surfer navigation analysis

“Hats off to you guys! The site looks just great. All of us at ACG want to thank you for making one fantastic site for us.

Now on to the next one! ”

Christie Murphy,
Armada Consulting Group,
www.armadacg.com Towson, MD

Contact

T: (301) 220-2455
info@bluewatermedia.com

Using your Email Address as Your Drupal Username

By: Matt Grasmick

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 madmatter23@grasmash.com, 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 theme or 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.

Tags: , , ,

Leave a Reply