[英]How to hash strings in python(django) and compare the hashed value with a given string
I'm working on a web app that allows users to sign up then login, I used the following functions to hash the password我正在开发一个 web 应用程序,该应用程序允许用户注册然后登录,我使用以下功能 hash 密码
from passlib.hash import pbkdf2_sha256
import math
def encrypt_password(pswd):
encrypt_pswd = pbkdf2_sha256.encrypt(pswd, rounds=(int(math.pow(len(pswd),3))), salt_size=(len(pswd)*2))
return encrypt_pswd
def verify_password(pswd, e_pswd):
en_pswd = encrypt_password(pswd)
if en_pswd == e_pswd:
return True
else:
return False
my problem is that the string I hashed doesn't produce the same result when I hash it for a second time.我的问题是,当我第二次使用 hash 时,我散列的字符串不会产生相同的结果。 How can I resolve this issue or what methods can I use hash the password, store in the database and compare that value with the one from the login form我该如何解决这个问题或者我可以使用什么方法 hash 密码,存储在数据库中并将该值与登录表单中的值进行比较
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.