python passlib密码验证

  sre, 开发


https://files.pythonhosted.org/packages/25/4b/6fbfc66aabb3017cd8c3bd97b37f769d7503ead2899bf76e570eb91270de/passlib-1.7.1.tar.gz

>>> # import the hash algorithm
>>> from passlib.hash import pbkdf2_sha256

>>> # generate new salt, and hash a password
>>> hash = pbkdf2_sha256.hash("toomanysecrets") # 加密一个字符串
>>> hash
'pbkdf2-sha25629000N2YMIWQsBWBMae09x1jrPQ1t8iyB2A.WF/Z5JZv.lfCIhXXN33N23OSgQYThBYRfk'

>>> # verifying the password
>>> pbkdf2_sha256.verify("toomanysecrets", hash) # 验证字符串,返回true
True
>>> pbkdf2_sha256.verify("joshua", hash)
False

LEAVE A COMMENT

Captcha Code