Index: django/contrib/auth/auth/__init__.py
===================================================================
Index: django/contrib/auth/auth/models.py
===================================================================
--- django/contrib/auth/auth/models.py	(revision 0)
+++ django/contrib/auth/auth/models.py	(revision 0)
@@ -0,0 +1,44 @@
+from django.core import validators
+from django.db import backend, connection, models
+from django.utils.translation import gettext_lazy as _
+from django.contrib.auth.models import Group, Permission, UserManager, UserTemplate
+
+class User(models.Model, UserTemplate):
+    """Users within the Django authentication system are represented by this model.
+
+    Username and password are required. Other fields are optional.
+    """
+    username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
+    first_name = models.CharField(_('first name'), maxlength=30, blank=True)
+    last_name = models.CharField(_('last name'), maxlength=30, blank=True)
+    email = models.EmailField(_('e-mail address'), blank=True)
+    password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]'"))
+    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
+    is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
+    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
+    last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
+    date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
+    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True, help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
+    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
+    objects = UserManager()
+
+    def __str__(self):
+        return self.username
+
+    class Meta:
+        verbose_name = _('user')
+        verbose_name_plural = _('users')
+        ordering = ('username',)
+        db_table = 'auth_user'
+        
+    class Admin:
+        fields = (
+            (None, {'fields': ('username', 'password')}),
+            (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
+            (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
+            (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
+            (_('Groups'), {'fields': ('groups',)}),
+        )
+        list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
+        list_filter = ('is_staff', 'is_superuser')
+        search_fields = ('username', 'first_name', 'last_name', 'email')
Index: django/contrib/auth/models.py
===================================================================
--- django/contrib/auth/models.py	(revision 4061)
+++ django/contrib/auth/models.py	(working copy)
@@ -3,6 +3,7 @@
 from django.db import backend, connection, models
 from django.contrib.contenttypes.models import ContentType
 from django.utils.translation import gettext_lazy as _
+from django.conf import settings
 import datetime
 
 def check_password(raw_password, enc_password):
@@ -82,44 +83,7 @@
         from random import choice
         return ''.join([choice(allowed_chars) for i in range(length)])
 
-class User(models.Model):
-    """Users within the Django authentication system are represented by this model.
-
-    Username and password are required. Other fields are optional.
-    """
-    username = models.CharField(_('username'), maxlength=30, unique=True, validator_list=[validators.isAlphaNumeric], help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
-    first_name = models.CharField(_('first name'), maxlength=30, blank=True)
-    last_name = models.CharField(_('last name'), maxlength=30, blank=True)
-    email = models.EmailField(_('e-mail address'), blank=True)
-    password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]'"))
-    is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site."))
-    is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
-    is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))
-    last_login = models.DateTimeField(_('last login'), default=models.LazyDate())
-    date_joined = models.DateTimeField(_('date joined'), default=models.LazyDate())
-    groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
-        help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
-    user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True, filter_interface=models.HORIZONTAL)
-    objects = UserManager()
-    class Meta:
-        verbose_name = _('user')
-        verbose_name_plural = _('users')
-        ordering = ('username',)
-    class Admin:
-        fields = (
-            (None, {'fields': ('username', 'password')}),
-            (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
-            (_('Permissions'), {'fields': ('is_staff', 'is_active', 'is_superuser', 'user_permissions')}),
-            (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
-            (_('Groups'), {'fields': ('groups',)}),
-        )
-        list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
-        list_filter = ('is_staff', 'is_superuser')
-        search_fields = ('username', 'first_name', 'last_name', 'email')
-
-    def __str__(self):
-        return self.username
-
+class UserTemplate:
     def get_absolute_url(self):
         return "/users/%s/" % self.username
 
@@ -240,7 +204,6 @@
         SiteProfileNotAvailable if this site does not allow profiles.
         """
         if not hasattr(self, '_profile_cache'):
-            from django.conf import settings
             if not settings.AUTH_PROFILE_MODULE:
                 raise SiteProfileNotAvailable
             try:
@@ -250,7 +213,22 @@
             except (ImportError, ImproperlyConfigured):
                 raise SiteProfileNotAvailable
         return self._profile_cache
+    
 
+# Grab the AUTH_USER_MODULE path and classname from the settings.
+# auth_user_module_parts[0] = module path
+# auth_user_module_parts[1] = class name
+auth_user_module_parts = settings.AUTH_USER_MODULE.rsplit('.', 1)
+auth_user_module = __import__(auth_user_module_parts[0], {}, {}, [auth_user_module_parts[0]])
+# Store the auth_user model so it is accessible with the standard 'from django.contrib.auth.models import User'
+User = getattr(auth_user_module, auth_user_module_parts[1])
+
+# Add the User model to the django db _app_models cache
+# These two lines allow the custom auth_user model to play nicely with syncdb and other systems that rely
+# on functions like django.db.models.loading.get_model(...)
+from django.db.models.loading import _app_models
+_app_models['auth'].update({'user':User})
+
 class Message(models.Model):
     """The message system is a lightweight way to queue messages for given users. A message is associated with a User instance (so it is only applicable for registered users). There's no concept of expiration or timestamps. Messages are created by the Django admin after successful actions. For example, "The poll Foo was created successfully." is a message.
     """
Index: django/conf/global_settings.py
===================================================================
--- django/conf/global_settings.py	(revision 4061)
+++ django/conf/global_settings.py	(working copy)
@@ -315,3 +315,6 @@
 # The name of the database to use for testing purposes.
 # If None, a name of 'test_' + DATABASE_NAME will be assumed
 TEST_DATABASE_NAME = None
+
+# The class to use as the default AUTH_USER for the authentication system.
+AUTH_USER_MODULE = 'django.contrib.auth.auth.models.User'
