- 
      
- 
        Save alejandrobernardis/5959e964899deb7d720f to your computer and use it in GitHub Desktop. 
    Async Password //// https://groups.google.com/d/msg/python-tornado/35BiBKdSCNw/zx561l-sABIJ
  
        
  
    
      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