Clone wiki

django-email-usernames / Home


django-email-usernames is an app that takes care of letting your django site use emails for logging in, like facebook, google and other major sites.

It consists of a email authentication backend, a email login form, a login view, and also a helper view that together with the popular django-registration app makes it simple for you to let users create new accounts with email as username.


1. First add it as any other django app, to your installed apps:


Obviously you also need to have the django.contrib.auth app in there, in order for authentication to be enabled.

2. Add the EmailOrUsernameModelBackend backend to AUTHENTICATION_BACKENDS in your settings:

    # Our custom auth backend that allows email addresses to be used as usernames.
    # Default auth backend that handles everything else.

3. This step is important! Because the built-in django username column in the auth_user table only allows 30 character long usernames by default, you need to modify it to be at least 75 characters. If you don't do this, emails that are longer than 30 characters long will be cut off, and this app will likely not work!

You can do this change either manually with SQL, or if you have not run syncdb for your site the first time, then django-email-usernames can try to do the change for you.

When you run python syncdb the first time, and the django.contrib.auth models are created for the first time, django-email-usernames will detect this and ask if you want to fix the username field in the auth_user table to be 75 chars long instead of 30 chars. Say yes in the prompt, and it will run the proper SQL for you. For this to work, the SQL user needs the ALTER TABLE privileges, otherwise you need to do the change manually (see way #1 above). This command will work with any database, including sqlite3.

Fork Updates

This fork requires Django 1.2 or higher. It adds support for django-registration 0.8 backends and the EmailLoginForm now extends AuthenticationForm. This allows almost everything to be taken care of from the urls.

The urls have moved to a more appropriate backends location and will need to be imported from: