I’ve packaged up django-email-as-username which should pretty much do everything you need if you’re looking to remove usernames, and only use emails.
The brief overview is:
- Provides an email auth backend and helper functions for creating users.
- Patches the Django admin to handle email based user authentication.
- Overides the createsuperuser command to create users with email only.
- Treats email authentication as case-insensitive.
Under the hood usernames are hashed versions of the emails, which ends up meaning we’re not limited to the Django’s username 30 char limit (Just the regular email 75 char limit.)
Edit: As of Django 1.5, you should look into using a custom User model instead of the ‘django-email-as-username’ package.
David Cramer came up with a solution to this problem that I love. I’m currently using it on a production site where the user has to be able to log in using their email OR their username. You can find it here:
If the login name provided on the form is an email (contains the ‘@’ symbol), it will attempt to authenticate with that, and will fall back on the username if it isn’t an email. (Naturally, you just need to make sure your registration form captures an email for this work.)
- Django prefetch_related's Prefetch, order_by?
- Sending a message to a single user using django-channels
- Django: Generic views based 'as_view()' method
- Can we have Django DateTimeField without timezone?
- Django + uWSGI + Nginx + SSL – request for working configuration (emphasis on SSL)
Well, I haven’t had to use emails as usernames in Django but I guess You could create a UserProfile model and aggregate fields to it, like another email field and make it unique. So you could do user.get_profile().email for your authentication.
I guess other way to go would be to inherit User and redefine the fields, but I think this still not recommended by Django developers.
Finally you could define your own custom User model and back on the django.contrib.auth.models.User for some logic.
Code to alter User table within Django:
from django.db import connection
cursor = connection.cursor()
cursor.execute("ALTER TABLE auth_user MODIFY COLUMN username varchar(75) NOT NULL")