简体   繁体   English

在Django中使用多个域中的相同密码创建用户

[英]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. 我有两个不同的域,abc.com和xyz.com这两个站点都使用django框架及其身份验证系统,我想创建一个用户名与xyz.com中的密码相同,以便该用户可以使用相同的凭据登录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: 一种选择是使用与xyz.com中相同的哈希密码创建用户,但是两个域在django的不同版本上运行(我已经在django版本1.6.3和1.7.2中测试了该方法)。我有以下问题:

  • 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. 关于集中式身份验证:您可以将数据库仅用于User模型。 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. 每个域都有一个会话cookie,它们将异步超时,但是将使用相同的密码和用户名来完成身份验证。

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. 您已经在两个项目中都设置了两个数据库,并仅为django用户创建了另一个数据库。

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. 它会帮助你。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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