Col*_*ean 3 python asynchronous tornado bcrypt pbkdf2
我正在使用PBKDF2,但这同样适用于BCrypt.
以合理的迭代次数散列密码可以轻松阻止0.5秒.什么是轻量级的方法来解决这个问题?我不愿意为此操作设置像Celery或Gearman这样的东西.
你可以使用一个线程.这不会阻止龙卷风.假设您有一个哈希密码的处理程序.那么两个相关的方法可能如下所示:
import threading
def on_message(self, message):
# pull out user and password from message somehow
thread = threading.Thread(target=self.hash_password, args=(user, password))
thread.start()
def hash_password(self, user, password):
# do the hash and save to db or check against hashed password
Run Code Online (Sandbox Code Playgroud)
您可以等待线程在on_message方法中完成然后编写响应,或者如果您不需要发送响应,那么只需让它完成并将结果保存在hash_password方法中.
如果你确实等待线程完成,你必须小心如何做到这一点.time.sleep会阻止所以你会想要使用龙卷风的非阻塞等待.