python 模块 passlib 加密密码串

Posted on Posted in python
文章目录[隐藏]

python 模块 passlib

passlib 官方文档

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

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

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

彩蛋

python -c 'from passlib.hash import sha512_crypt; import getpass; print (sha512_crypt.encrypt(getpass.getpass()))'

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + 8 =