Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:34:17+00:00 2026-05-30T20:34:17+00:00

I don’t want to write custom auth backend and I think such common task

  • 0

I don’t want to write custom auth backend and I think such common task must been already solved by some 3rd party app.

I did some googling and skimming through SO but found only https://bitbucket.org/hakanw/django-email-usernames/wiki/Home which is quite old (2008). Are any other alternatives already available?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:34:18+00:00Added an answer on May 30, 2026 at 8:34 pm

    You say, "I don’t want to write custom auth backend" but a custom authentication backend is exactly the way that Django expects you to solve this problem, and moreover, it’s really quite straightforward—much simpler than installing a third-party app.

    Here’s a simple approach, in which a user has one e-mail address, stored in the email field of the built-in User object.

    First, think about case-sensitivity. Even though the local part of an e-mail address (the part before the @ sign) may be case-sensitive (depending on the e-mail provider), Django’s built-in auth application treats e-mail addresses as being case-insensitive (for example, when deciding which users to e-mail in response to a password reset request). So it’s probably best for you to treat them that way too.

    Second, ensure that two users can’t share the same e-mail address. You could do this by hand in the database:

    ALTER TABLE auth_user ADD UNIQUE INDEX (email);
    

    or if you are using South, then make a schema migration for the auth application where you call db.create_unique('auth_user', 'email').

    To enforce case-insensitive uniqueness, you should ensure that the collation on the email field is case-insensitive. I found that it already was, but you might do something like:

    ALTER TABLE auth_user MODIFY email VARCHAR(75) COLLATE utf8_general_ci;
    

    (Or ascii_general_ci if you don’t support international e-mail addresses.)

    Third, define your authentication backend, perhaps in mysite/backends.py:

    from django.contrib.auth.backends import ModelBackend
    from django.contrib.auth.models import User
    
    class EmailAuthenticationBackend(ModelBackend):
        """
        Authenticate against django.contrib.auth.models.User using
        e-mail address instead of username.
        """
        def authenticate(self, username=None, password=None):
            try:
                user = User.objects.get(email__iexact = username)
                if user.check_password(password):
                    return user
            except User.DoesNotExist:
                return None
    

    Fourth, add your authentication backend to your settings.py:

    AUTHENTICATION_BACKENDS = ('mysite.backends.EmailAuthenticationBackend',)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this has been answered before. Have custom routes to users. If
Don't know how to google for such, but is there a way to query
I don't want PHP errors to display /html, but I want them to display
Don't know if I worded the question right, but basically what I want to
Don't know if this has been asked before, so point me to another question
Don't think that I'm mad, I understand how php works! That being said. I
Don't think my virtualhost is working correctly. This is what I have inside of
Don't get me wrong, I want them to get saved. But I always thought
I don't know if this has been asked before, but what i'd like to
I don't like Jackson. I want to use ajax but with Google Gson. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.