[英]Storing the customized django auth_user model
I am working on a website and for the login information, I am using a customized MyUser
model that is a subclass of the original User
model. 我正在一个网站上工作,对于登录信息,我使用的是自定义MyUser
模型,该模型是原始User
模型的子类。 Now, to create MyUser
records, i use 现在,要创建MyUser
记录,我使用
x = MyUser.objects.create(
username = #something,
password = #something,
...
)
x.save()
etc. Now, the MyUser record is created. 等等。现在,创建MyUser记录。 But when I go to my admin page, I see type of password as: 但是,当我进入管理页面时,我看到的密码类型为:
Invalid password format or unknown hashing algorithm.
And authenticate(username,password)
returns None and it works properly only if i go to admin and change the password. 和authenticate(username,password)
返回None,并且只有当我去admin并更改密码时它才能正常工作。 What is the best solution to store the MyUser
data in the database? 将MyUser
数据存储在数据库中的最佳解决方案是什么?
Use the set_password
functionality provided by django User
使用django User
提供的set_password
功能
x = MyUser.objects.create(
username = #something,
...
)
x.set_password(#something)
x.save()
Now, set_password
would apply the hashing algorithm, and store the encrypted password for you, where as what you are doing would just set the plain text password, which is the issue. 现在, set_password
将应用哈希算法,并为您存储加密的密码,而您正在做的只是设置纯文本密码,这就是问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.