Edit

Template Coding Drupal Insert email as username at registration

<?php
function HOOK_user_insert( &$edit, &$account, $category = NULL ){

    // Don't create a new username if one is already set
    if( strpos($account->name, 'temporary_') !== 0)
        return;

    // Otherwise, replace username with email address field
    db_update("users")
        ->fields(array("name" => $edit["mail"]))
        ->condition("uid", $account->uid)
        ->execute();

    $edit["name"] = $edit["mail"];
    $account->name = $edit["mail"];
    return;
}


function HOOK_user_register_form_alter( &$form, &$form_state, $form_id ){

    $form["account"]["name"]["#value"] = "temporary_".user_password();
    $form["account"]["name"]["#access"] = FALSE;

}?>