1.6.2 BSD License    
  not rated
User authentication with email addresses instead of usernames




django-email-as-username is a Django app that allows you to treat users as having only email addresses, instead of usernames.

- 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.


Install from PyPI:

pip install django-email-as-username

Add 'emailusernames' to INSTALLED_APPS.


Set EmailAuthBackend as your authentication backend:



Creating users

You should create users using the create_user and create_superuser functions.

from emailusernames.utils import create_user, create_superuser

create_user('', 'password')
create_superuser('', 'password')

Retrieving users

You can retrieve users, using case-insensitive email matching, with the get_user function. Similarly you can use user_exists to test if a given user exists.

from emailusernames.utils import get_user, user_exists

user = get_user('')

if user_exists(''):

Updating users

You can update a user's email and save the instance, without having to also modify the username. = ''

Note that the user.username attribute will always return the email address, but behind the scenes it will be stored as a hashed version of the user's email.

Authenticating users

You should use email and password keyword args in calls to authenticate, rather than the usual username and password.

from django.contrib.auth import authenticate

user = authenticate(email='', password='password')
if user:

User Forms

emailusernames provides the following forms that you can use for authenticating, creating and updating users:

- emailusernames.forms.EmailAuthenticationForm
- emailusernames.forms.EmailAdminAuthenticationForm
- emailusernames.forms.UserCreationForm
- emailusernames.forms.UserChangeForm

Using Django's built-in login view

If you're using django.contrib.auth.views.login in your urlconf, you'll want to make sure you pass through EmailAuthenticationForm as an argument to the view.

urlpatterns = patterns('',
 url(r'^auth/login$', 'django.contrib.auth.views.login',
 {'authentication_form': EmailAuthenticationForm}, name='login'),
Last updated on July 10th, 2012

0 User reviews so far.