From 83c2f481079f4ea62f543be10b8867b4ca1c0c42 Mon Sep 17 00:00:00 2001 From: Tristan Olive Date: Mon, 19 Mar 2012 11:52:47 -0400 Subject: [PATCH] Just append an incrementing digit to non-unique names --- .../modules/boincuser/includes/boincuser.forms.inc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc b/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc index 2e822fd8c1..9d44c71330 100644 --- a/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc +++ b/drupal/sites/default/boinc/modules/boincuser/includes/boincuser.forms.inc @@ -119,9 +119,15 @@ function boincuser_create_drupal_user($boinc_user) { BoincForumPrefs::lookup($boinc_user); $account = null; $module = 'boincuser'; - // Convert non-unique name to effectively-unique - $timestamp = dechex(substr(microtime(),2,6)); - $unique_name = substr($boinc_user->name, 0, 54) . "_{$timestamp}"; + + // Make sure name is unique + $unique_name = $boinc_user->name; + $same_name_tally = 1; + while (db_result(db_query("SELECT uid FROM users WHERE name = '{$unique_name}' LIMIT 1"))) { + $same_name_tally++; + $unique_name = "{$boinc_user->name} {$same_name_tally}"; + } + // Email is limited to 64 characters... $boinc_email = substr($boinc_user->email_addr, 0, 64); $userinfo = array(