diff --git a/webserver_auth.module b/webserver_auth.module
index e183acc..f234383 100644
--- a/webserver_auth.module
+++ b/webserver_auth.module
@@ -65,9 +65,12 @@ function webserver_auth_route() {
   elseif (isset($_SERVER ['REMOTE_USER'])) {
     $authname = $_SERVER ['REMOTE_USER'];
   }
- 
+
+  if ($authname) {
+    drupal_alter('webserver_auth_authname', $authname);
+  }
+
   if ($authname) {
-    $authname = webserver_auth_prepare_username($authname);
       
     if (webserver_auth_attempt_login($authname)) {
       return;
@@ -234,9 +237,11 @@ function webserver_auth_form_user_profile_form_alter(&$form, &$form_state, $form
 }
 
 /**
+ * Implements hook_webserver_auth_authname_alter()
+ *
  * Strip the prefix and suffix from the username according to the settings.
  */
-function webserver_auth_prepare_username($username) {
+function webserver_auth_webserver_auth_authname_alter(&$username) {
   if (variable_get('webserver_auth_strip_prefix', TRUE)) {
     $fields = explode("\\", $username);
     $username = $fields [count ($fields) - 1];
@@ -245,5 +250,4 @@ function webserver_auth_prepare_username($username) {
     $fields = explode ('@', $username);
     $username = $fields [0];
   }
-  return $username;
-}
\ No newline at end of file
+}
