簡體   English   中英

使用哈希密碼進行django身份驗證或將其轉換為純文本

[英]django authentication with hashed password or convert it to plain

可以說我有用戶的電子郵件

user = User.objects.get(email="anyone@anymail.com")

現在,我要像這樣登錄該用戶:

user = authenticate(username=username, password=user.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

根據文檔,

set_password(原始密碼)
將用戶的密碼設置為給定的原始字符串,並注意密碼哈希。 不保存用戶對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM