def login(cls, username, password): user = cls.get_by_name(username) if user: salt = user.salt correct_hash = user.pw_hash new_hash = hashpw(password, salt)[0] if correct_hash == new_hash: return user
def register(cls, username, password, email = None): pw_hash, salt = hashpw(password) return User(username = username, pw_hash = pw_hash, salt = salt, email = email)