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 7078995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:36:58+00:00 2026-05-28T06:36:58+00:00

I have used Django before (version 1.2) and generally I like it… it is

  • 0

I have used Django before (version 1.2) and generally I like it… it is especially good at getting a brand new project up and running quickly. But, in this case, I’m rewriting and existing system and moving it to Python/Django. So, I already have a MySQL database that has a “users” table in it… this table stores the user’s password with the MySQL SHA1 function (no salt, etc).

As part of the migration, I’m going to fix some of the data modeling flaws and port to PostgreSQL.

I would really like to use django.contrib.auth, but I’m unclear what I need to do. I have read the documentation, and know that I can separate the required user information and the “extra” information I have and put it into UserProfile.

But, how to handle the passwords stored in the MySQL db?

Has anyone handled this before? What approach did you take?

  • 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-28T06:36:59+00:00Added an answer on May 28, 2026 at 6:36 am

    Here is what I did to get things working. I created a custom authentication backend. Note: I’m using the email address as the username.

    Here is my code:

    from django.db.models import get_model
    from django.contrib.auth.models import User
    from hashlib import sha1
    
    class MyUserAuthBackend(object):
    
        def check_legacy_password(self, db_password, supplied_password):
            return constant_time_compare(sha1(supplied_password).hexdigest(), db_password)
    
    
        def authenticate(self, username=None, password=None):
            """ Authenticate a user based on email address as the user name. """
            try:
                user = User.objects.get(email=username)
    
                if '$' not in user.password:
                    if self.check_legacy_password(user.password, password):
                        user.set_password(password)
                        user.save()
                        return user
                    else:
                        return None
    
                else:
                    if user.check_password(password):
                        return user
    
            except User.DoesNotExist:
                return None
    
    
        def get_user(self, user_id):
            """ Get a User object from the user_id. """
            try:
                return User.objects.get(pk=user_id)
            except User.DoesNotExist:
                return None
    

    Then I added the following to settings.py:

    AUTHENTICATION_BACKENDS = (
        'my_website.my_app.my_file.MyUserAuthBackend',
    )
    

    The suggestion from @Dougal appears to be for the next release of Django and was not available for me (I’m using 1.3.1). However, it seems like it will be a better solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using django-appengine and am now trying a project with django-nonrel. Before
I used django 1.2 before and didn't have any problem switching language... In my
I have used traditional version control systems to maintain source code repositories on past
I have used the XML Parser before, and even though it worked OK, I
I have Django project on Dreamhost server which has several views that returns Json
I have a simple Django-Piston Handler that creates a new instance of a model
Is there a way to detect unused templates in a Django project? Before Django
I have a standard Django Admin page that is used to upload multiple files.
I have a site running on django, (but the question applies to anything, php,
I have gone similar threads like Django persistent database connection and other stuff on

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.