Last active
August 29, 2015 14:09
-
-
Save abdelouahabb/37ac7cda36cd57e3cef4 to your computer and use it in GitHub Desktop.
how to use tornado with password hashing, original link https://groups.google.com/forum/#!topic/python-tornado/35BiBKdSCNw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from concurrent.futures import ThreadPoolExecutor | |
from tornado import gen | |
from tornado.process import cpu_count | |
import bcrypt | |
# global threadpool | |
pool = ThreadPoolExecutor(cpu_count()) | |
@gen.coroutine | |
def create_user(name, password): | |
hashed_pw = yield pool.submit(bcrypt.hashpw, password, bcrypt.gensalt()) | |
yield save_user(name, hashed_pw) | |
@gen.coroutine | |
def login(name, password): | |
user = yield load_user(name) | |
match = yield pool.submit(bcrypt.checkpw, password, user.hashed_pw) | |
if not match: | |
raise IncorrectPasswordError() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment