mirror of
https://github.com/simple-login/app.git
synced 2024-11-18 01:40:38 +01:00
372466ab06
- add __tablename__ for all models - use sa and orm instead of db - rollback all changes in tests - remove session in @app.teardown_appcontext
21 lines
632 B
Python
21 lines
632 B
Python
import bcrypt
|
|
import sqlalchemy as sa
|
|
import unicodedata
|
|
|
|
_NORMALIZATION_FORM = "NFKC"
|
|
|
|
|
|
class PasswordOracle:
|
|
password = sa.Column(sa.String(128), nullable=True)
|
|
|
|
def set_password(self, password):
|
|
password = unicodedata.normalize(_NORMALIZATION_FORM, password)
|
|
salt = bcrypt.gensalt()
|
|
self.password = bcrypt.hashpw(password.encode(), salt).decode()
|
|
|
|
def check_password(self, password) -> bool:
|
|
if not self.password:
|
|
return False
|
|
|
|
password = unicodedata.normalize(_NORMALIZATION_FORM, password)
|
|
return bcrypt.checkpw(password.encode(), self.password.encode())
|