#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 Changed 11 years ago by
Needs tests: | set |
---|---|
Owner: | changed from nobody to Evgeniy Makhmudov |
Status: | new → assigned |
comment:2 Changed 11 years ago by
Owner: | Evgeniy Makhmudov deleted |
---|---|
Status: | assigned → new |
comment:3 Changed 11 years ago by
Owner: | set to Evgeniy Makhmudov |
---|---|
Status: | new → assigned |
comment:4 Changed 11 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
comment:5 Changed 11 years ago by
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?
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.]