--- uc_affiliate2.user.inc	2010-08-26 22:32:07.000000000 -0600
+++ uc_affiliate2.user.inc.new	2010-08-26 22:26:40.000000000 -0600
@@ -113,7 +113,12 @@ function uc_affiliate2_dashboard($accoun
               example.com/!path/!uid/node/1', array('!uid' => $account->uid, '!path' => variable_get('uc_affiliate2_path', 'affiliate'))) . '<br /> <br />';
 
   $text_link = variable_get('affiliate_text_link_template', '');
-  $text_link = l($text_link, variable_get('uc_affiliate2_path', 'affiliate'). '/'. $account->uid, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE, 'html' => TRUE));
+  // The key for affiliate links defaults to [uid]
+  // however, this can be overridden by adding the following line
+  // $conf['uc_affiliate2_userkey'] = 'name'
+  // in the site's settings.php file to use the username instead.
+  $userkey = variable_get('uc_affiliate2_userkey', 'uid');
+  $text_link = l($text_link, variable_get('uc_affiliate2_path', 'affiliate'). '/'. $account->$userkey, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE, 'html' => TRUE));
   $output .= '<b>' . t('Text Link:') . '</b> <br /> <textarea cols="45">'. $text_link .'</textarea>';
 
   $output .= _uc_affiliate2_display_banners();
@@ -263,6 +268,11 @@ function _uc_affiliate2_product_form_sub
 
 function _uc_affiliate2_display_banners() {
   global $base_url, $user;
+  // The key for affiliate links defaults to [uid]
+  // however, this can be overridden by adding the following line
+  // $conf['uc_affiliate2_userkey'] = 'name'
+  // in the site's settings.php file to use the username instead.
+  $userkey = variable_get('uc_affiliate2_userkey', 'uid'); //
 
   $banners = variable_get('affiliate_banner_template', '');
 
@@ -278,7 +288,7 @@ function _uc_affiliate2_display_banners(
 
   foreach ($banners as $banner) {
     $banner = '<'. $banner;
-    $banner_link = l($banner, variable_get('uc_affiliate2_path', 'affiliate') .'/'. $user->uid, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE, 'html' => TRUE));
+    $banner_link = l($banner, variable_get('uc_affiliate2_path', 'affiliate') .'/'. $user->$userkey, array('query' => NULL, 'fragment' => NULL, 'absolute' => TRUE, 'html' => TRUE));
 
     $line = array();
     $line[] = $banner;
