[英]How do I store a hashed password on Django and how do i compare with another hashed password?
我一直在尋找一種存儲哈希的方法,但我仍然沒有在 models.py 中找到正確的方法
模型.py
class QL_USR_DT(models.Model):
ql_usr_img_link=models.ImageField(upload_to="user-profile-picture")
ql_usr_name=models.CharField(max_length=60)
ql_usr_email=models.EmailField()#By default the max_Length is 254
ql_usr_pass=models.CharField(max_length=254)
ql_usr_username=models.CharField(max_length=30)
gender = (
("M","Male"),
("F","Female"),
)
ql_usr_gender = models.CharField(max_length=1, choices=gender, default="M", null=False)
ql_usr_created=models.DateTimeField(auto_now_add=True)
設置.py
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]
如果你真的想在你自己的模型中自己管理密碼,你可以這樣做:
from django.contrib.auth.hashers import make_password, check_password
your_password = make_password("plain_text")
check_password("plain_text",your_password)
並將該哈希存儲在數據庫中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.