from werkzeug.security import generate_password_hash, check_password_hash class User(object): name="vincent" password=generate_password_hash("test", method='sha256') id=1 # def __init__(self, name, password): # self.name = name # self.password = generate_password_hash(password, method='sha256') @classmethod def authenticate(cls, **kwargs): name = kwargs.get('name') password = kwargs.get('password') if not name or not password: return None user = cls if not user or not check_password_hash(user.password, password): return None return user def to_dict(self): return dict(id=self.id, name=self.name)