这段代码应该用盐哈希密码.salt和哈希密码正在保存在数据库中.密码本身不是.
考虑到操作的敏感性,我想确保一切都是犹太洁食.
注意:我习惯使用url安全版的b64encode.
import hashlib
import base64
import uuid
password = 'test_password'
salt = base64.urlsafe_b64encode(uuid.uuid4().bytes)
t_sha = hashlib.sha512()
t_sha.update(password+salt)
hashed_password = base64.urlsafe_b64encode(t_sha.digest())
Run Code Online (Sandbox Code Playgroud) 对于大多数面向公众的服务,您通常可以在用户开始恼火之前注册250ms - 400ms.
那么,如果我们认为对于登录尝试有一次数据库调用,它rounds在登录/注册中的最佳价值是什么,并且它使用MongoDB进行非阻塞调用.(使用Mongotor,并使用电子邮件作为,因此它默认索引,查询很快:0.00299978256226,当然使用具有3条记录的数据库测试...)_id
import passlib.hash
import time
hashh = passlib.hash.pbkdf2_sha512
beg1 = time.time()
password = hashh.encrypt("test", salt_size = 32, rounds = 12000)
print time.time()- beg1 # returns 0.142999887466
beg2 = time.time()
hashh.verify("test", password) # returns 0.143000125885
print time.time()- beg2
Run Code Online (Sandbox Code Playgroud)
现在,如果我使用半值:
password = hashh.encrypt("test", salt_size = 32, rounds = 4000) # returns 0.0720000267029
hashh.verify("test", password) # returns 0.0709998607635
Run Code Online (Sandbox Code Playgroud)
我 …