[英]django authentication with hashed password or convert it to plain
Lets say I have email of user 可以说我有用户的电子邮件
user = User.objects.get(email="anyone@anymail.com")
Now I want to login this user like: 现在,我要像这样登录该用户:
user = authenticate(username=username, password=user.password)
Authenticate do not take hashed password. 验证时不要使用哈希密码。 But here i can only get hashed password.
但是在这里我只能得到哈希密码。 How can I login this user lets say to change its password
我如何登录该用户,可以说要更改其密码
Thank you 谢谢
You don't need to log in a user to change the password. 您无需登录用户即可更改密码。 You can use the Django's
set_password()
helper function to change the password. 您可以使用Django的
set_password()
帮助函数来更改密码。
from django.contrib.auth.models import User
user = User.objects.get(email="anyone@anymail.com")
user.set_password('new_password')
user.save() # call save explicitly
As per the docs, 根据文档,
set_password(raw_password)
set_password(原始密码)
Sets the user's password to the given raw string, taking care of the password hashing.将用户的密码设置为给定的原始字符串,并注意密码哈希。 Doesn't save the User object.
不保存用户对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.