Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
I've only used the D6 version, but here is the way to do it with this version. (In a custom module)
<?php
/**
* Implementation of hook_email_registration_name();
*
* Generates a user name based on the user uid of the
* new user.
*/
function HOOK_email_registration_name($edit, $account) {
// sprintf pads the number to a length of 7 characters
// e.g. uid = 25 becomes 0000025
return 'Add a prefix here'. sprintf('%07s', $account->uid) .'or a suffix';
}
?>
If this works in Drupal 5, change the component of this issue to "Documentation" and status to "Needs work"
Hello Alan D.
I also use D6 - if I activate a custom module with the above code now, but already have members on my site, will the current user's usernames change as well? If not, how can I get all current and new users to go with the username=uid rule?
Thanks for your help.
you would need to add an update script or do a manual sql query.
In the file HOOK.install (HOOK for module name)
Never run and is not been tested!!!!
<?php
function HOOK_update_6000() {
$ret = array();
// Notice that the uid > 1 prevents this from changing the admin username
$q = db_query("SELECT uid, name FROM {users} WHERE uid > 1");
while ($account = db_fetch_object($q)) {
$name = HOOK_email_registration_name(array(), $account);
db_query("UPDATE {users} SET name = '%s' WHERE uid = %d", $name, $account->uid);
}
return $ret;
}
?>
Two other issues found:
The early emails will also have the wrong user name too.
The path alias is also generated incorrectly using the old name.
Comments
Comment #1
Bilmar commentedThis would be a great new feature! Having option to use UID or UID as 7 digit number etc; ie 0000001, 0000002, 0000003...
Comment #2
alan d. commentedI've only used the D6 version, but here is the way to do it with this version. (In a custom module)
If this works in Drupal 5, change the component of this issue to "Documentation" and status to "Needs work"
:)
Comment #3
Bilmar commentedHello Alan D.
I also use D6 - if I activate a custom module with the above code now, but already have members on my site, will the current user's usernames change as well? If not, how can I get all current and new users to go with the username=uid rule?
Thanks for your help.
Comment #4
alan d. commentedyou would need to add an update script or do a manual sql query.
In the file HOOK.install (HOOK for module name)
Never run and is not been tested!!!!
Two other issues found:
Comment #5
YK85 commentedcan someone please help to make this feature work in the latest D6 dev?
thanks!
Comment #6
YK85 commentedkindly bumping to be considered as a new feature in Email Registration where options for the username can be pre-determined.
Comment #7
gregglesIt's possible to do this yourself with a custom hook_email_registration_name in a site-specific module.
I don't think this makes sense for the module itself to do.