Mercurial > piecrust2
comparison piecrust/admin/bcryptfallback.py @ 1176:28c388fc18b2
cm: Upgrade flask-login and flask-bcrypt.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 21 May 2020 22:04:35 -0700 |
parents | 0d699f04968c |
children |
comparison
equal
deleted
inserted
replaced
1175:d0f86d9a9d40 | 1176:28c388fc18b2 |
---|---|
19 | 19 |
20 | 20 |
21 try: | 21 try: |
22 from flask_bcrypt import Bcrypt | 22 from flask_bcrypt import Bcrypt |
23 except ImportError: | 23 except ImportError: |
24 print_warning = True | 24 try: |
25 from flask.ext.bcrypt import Bcrypt | |
26 except ImportError: | |
27 print_warning = True | |
25 | 28 |
26 def generate_password_hash(password): | 29 def generate_password_hash(password): |
27 return hashlib.sha512(password.encode('utf8')).hexdigest() | 30 return hashlib.sha512(password.encode('utf8')).hexdigest() |
28 | 31 |
29 def check_password_hash(reference, check): | 32 def check_password_hash(reference, check): |
30 check_hash = hashlib.sha512(check.encode('utf8')).hexdigest() | 33 check_hash = hashlib.sha512(check.encode('utf8')).hexdigest() |
31 return check_hash == reference | 34 return check_hash == reference |
32 | 35 |
33 class SHA512Fallback(object): | 36 class SHA512Fallback(object): |
34 is_fallback_bcrypt = True | 37 is_fallback_bcrypt = True |
35 | 38 |
36 def __init__(self, app=None): | 39 def __init__(self, app=None): |
37 self.generate_password_hash = generate_password_hash | 40 self.generate_password_hash = generate_password_hash |
38 self.check_password_hash = check_password_hash | 41 self.check_password_hash = check_password_hash |
39 | 42 |
40 def init_app(self, app): | 43 def init_app(self, app): |
41 app.bcrypt = self | 44 app.bcrypt = self |
42 | 45 |
43 Bcrypt = SHA512Fallback | 46 Bcrypt = SHA512Fallback |
44 | 47 |
45 | 48 |
46 if print_warning: | 49 if print_warning: |
47 logging.warning("Bcrypt not available... falling back to SHA512.") | 50 logging.warning("Bcrypt not available... falling back to SHA512.") |
48 logging.warning("Run `pip install Flask-Bcrypt` for more secure " | 51 logging.warning("Run `pip install Flask-Bcrypt` for more secure " |