我怎样才能散列旋风最小拦截密码?(How can I hash a password in Torn

2019-08-02 00:44发布

我使用PBKDF2 ,但是这同样适用于BCrypt。

与迭代的合理数量的散列密码可以很容易地阻止0.5秒。 什么是借此出过程的轻量级的方式? 我不愿意建立像芹菜或Gearman的只是进行此项操作。

Answer 1:

你可以使用一个线程。 这不会阻止龙卷风。 你说你有一个散列密码的处理程序。 那么这两个相关的方法可能是这样的:

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

您既可以等待线程在完成on_message方法然后写响应,或者如果你并不需要发送一个响应,那么就让它完成并保存在结果hash_password方法。

如果等待线程来完成你有你如何做到这一点要小心。 time.sleep将阻止,所以你会希望使用龙卷风非阻塞的等待吧。



文章来源: How can I hash a password in Tornado with minimal blocking?