#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 , 12 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:2 by , 12 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:3 by , 12 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 12 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
comment:5 by , 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?
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.]