While looking at the project page of Email Registration, it reads:
A username is generated and assigned based on the user name part of
the email address and their user ID. Sites that want to create
usernames in their own way can do so by implementing
hook_email_registration_name.
And when looking at hook_email_registration_name(), we see how we can alter the username by returning a value.
So, what you need to do is:
- Create a custom module (there is plenty of documentation for that on this site and the rest of the internet).
- Implement hook_email_registration_name() (place this function in your module file and replace
hook
with your module name).
- Have the hook return a new username.
So you need to put something like this in your module file:
function mymodule_email_registration_name($edit, $account) {
$mail = $edit['mail'];
$mail_parts = explode('@', $mail);
$username = $mail_parts[0];
return email_registration_cleanup_username($username);
}
This will return the first part of the email as the username. So [email protected]
becomes john
. [email protected]
becomes bob
. [email protected]
becomes also john
... But that was already in use and Drupal does not allow duplicate usernames, so you have a problem. (And you discovered the reason this module by default appends a unique token to the username.)
You could solve this by implementing a small iterator. Appending 1, 2, 3 to every subsequent John but it would result in just as ugly usernames (and for the 100th john you had to do 99 database lookups making this slow).
So I'd like to propose to you Real Name. This nifty module will override the username display everywhere with the value of one or more other profile field. So you add a namefield to the registration, configure Real Name to use that field and the user will never know his username is john_123
because he will never see it.
I don't know your specific requirements and this might not be suitable for you, or if you can think of another way to enforce uniqueness, you can always use the hook and implement your own method. See what fits you :).