簡體   English   中英

gevent和強哈希密碼方法

[英]gevent and strong hashing password method

我正在使用gevent greenlet,因此我對與CPU計算相關的所有事情都感到非常困惑。 而且我需要使用一種強大的哈希方法來存儲密碼。

當我不在gevent上下文中時,我有使用bcrypt的習慣,但是我做了一個小測試:

import bcrypt
import time

password = b"toto"

start_hash  = time.clock()

hashed = bcrypt.hashpw(password, bcrypt.gensalt())

print 'time hash bcrypt %s' % (time.clock() - start_hash)

start_compare = time.clock()

assert bcrypt.hashpw(password, hashed) == hashed

elapsed = (time.clock() - start_compare)

print 'time check bcrypt %s' % elapsed

結果是:

time hash bcrypt 0.291887
time check bcrypt 0.293343

就像在greenlet中一樣,這花費了太多時間以致無法使用。

作為比較,使用舊md5哈希的相同類型的計算:

time hash md5 4.1e-05
time check hash md5 1.1e-05

我有什么解決方案?

Gevent與利用並發性的網絡和IO綁定功能配合良好,但bcrypt沒有此功能。

嘗試使用Processlet和ObjectPool。 Processlet專注於CPU綁定的任務,例如哈希,而不是IO綁定的任務。 這里可以找到將bcrypt與Processlet和ObjectPool結合使用的一個很好的例子。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM