Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19912 closed New feature (wontfix)

Authenticate users in multiple database

Reported by: Evgeniy Makhmudov Owned by: Evgeniy Makhmudov
Component: contrib.auth Version: 1.4
Severity: Normal Keywords: authenticate
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

A problem occur while using several database (each contains users tables) and don't using managers. Process authentication in Django is avaiable only for users table in default database. My proposal is in small modification in original (1.4) code:

# django.contrib.auth.backends.py
# class ModelBackend(object)
# ... 

    def authenticate(self, username=None, password=None, database='default'):
        try:
            user = User.objects.using(database).get(username=username)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

I don't tested this from global point of view, but in my app it is working.

Change History (5)

comment:1 by Evgeniy Makhmudov, 12 years ago

Needs tests: set
Owner: changed from nobody to Evgeniy Makhmudov
Status: newassigned

comment:2 by Evgeniy Makhmudov, 12 years ago

Owner: Evgeniy Makhmudov removed
Status: assignednew

comment:3 by Evgeniy Makhmudov, 12 years ago

Owner: set to Evgeniy Makhmudov
Status: newassigned

comment:4 by Jacob, 12 years ago

Resolution: wontfix
Status: assignedclosed

I think this is in "write your own backend" territory. It's fairly simple to subclass ModelBackend and provide your own authentication using whatever database you choose. Once you start doing "special things" with auth, you're almost certainly going to have to write a custom backend.

[Also, this mixes up what arguments authenticate() takes: it's supposed to be **credentials, but the database isn't exactly considered credentials, I think.]

comment:5 by Evgeniy Makhmudov, 12 years ago

about first, ok. I understand.

about this:
[Also, this mixes up what arguments authenticate() takes: it's supposed to be **credentials, but the database isn't exactly considered credentials, I think.]

i don't understand, why it problem for authenticate()? Look, django.contrib.auth.authenticate takes **credentials and send it to backend, which by default alwsays the only 'django.contrib.auth.backends.ModelBackend'. This backend receive dictionary with needed username,password and if neccesseary database name, otherwise use predefault value 'default'. So, i can't see where is mixing?

Note: See TracTickets for help on using tickets.
Back to Top