Files
notifications-api/app/encryption.py
Leo Hemsted 43bda1ae2c upgrade flask-bcrypt to 0.7.1
this uses bcrypt directly rather than using the wrapper python-bcrypt.
WARNING! You'll need to update your local install by running:

```
pip uninstall python-bcrypt
pip install flask-bcrypt==0.7.1
```
2017-09-11 15:47:10 +01:00

25 lines
786 B
Python

from flask_bcrypt import generate_password_hash, check_password_hash
from itsdangerous import URLSafeSerializer
class Encryption:
def init_app(self, app):
self.serializer = URLSafeSerializer(app.config.get('SECRET_KEY'))
self.salt = app.config.get('DANGEROUS_SALT')
def encrypt(self, thing_to_encrypt):
return self.serializer.dumps(thing_to_encrypt, salt=self.salt)
def decrypt(self, thing_to_decrypt):
return self.serializer.loads(thing_to_decrypt, salt=self.salt)
def hashpw(password):
return generate_password_hash(password.encode('UTF-8'), 10).decode('utf-8')
def check_hash(password, hashed_password):
# If salt is invalid throws a 500 should add try/catch here
return check_password_hash(hashed_password, password)