简体   繁体   中英

Creating user in django with same password in multiple domains

I have two different domains say,abc.com and xyz.com both sites are using django framework and its authentication system , and I want to create a user with same password as in xyz.com so that the user can login using same credentials of abc.com.

One alternative is to create the user with same hashed password as in xyz.com but the two domains runs on different versions of django(I have tested the approach in django versions 1.6.3 and 1.7.2).I have following questions:

  • What are the consequences(future problems) of using the above approach?
  • Is there any other better alternative/approaches to create centralized authentication system if user database is not centralized.

Also I do not want to add custom password field, or store in user's sessions or manage password from my end.

Regarding centralized authentication: you could use the database for just the User model. Multiple databases has been supported for some time, and you can read about it here .

There will be a session cookie for each domain, and they will time-out asynchronously, but the authentication will be done using the same password and username.

You should make centralized database.If you don't want to do that. You have set-upped both database in both projects and create another one database for django user only.

settings like:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.xxx',
        'NAME': 'djangoUserDB',                 
        'USER': 'root',                    
        'PASSWORD': '',                
        'HOST': 'abc or xyz', # you should put this in one domain. abc or xyz               
        'PORT': '',
    },

    'abc': {
        'ENGINE': 'django.db.backends.xxx',
        'NAME': 'abcDB',                 
        'USER': 'root',                    
        'PASSWORD': '',                
        'HOST': 'abc', 
        'PORT': '',
    },

   'xyz': {
        'ENGINE': 'django.db.backends.xxx',
        'NAME': 'abcDB',                 
        'USER': 'root',                    
        'PASSWORD': '',                
        'HOST': 'xyz',         'PORT': '',
     },
}

You should use only one db for user management.

I don't think so any problem will happened.

Hopefully! it will help you. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM