def login(self, credentials: dict) -> dict: schema = AdminLoginSchema() try: credentials = schema.load(credentials) storedAdmin = Admin.query.filter_by(username=credentials["username"]).first() if storedAdmin is None: return None isLogged = Utils.verify_password( storedAdmin.password[0], storedAdmin.password[1], credentials["password"] ) if not isLogged: return None data = AdminCreateSchema().dump(storedAdmin) tokens = Auth.generate_session_token("ADMIN", **data) except ValidationError as e: raise InvalidParametersError(e.data, e.messages, "Error occurred when trying to loggin admin", e) return tokens
def login(self, credentials: dict) -> dict: schema = UserLoginSchema() try: credentials = schema.load(credentials) storedUser = User.query.filter_by(email=credentials["email"]).first() if storedUser is None: return None isLogged = Utils.verify_password( storedUser.password[0], storedUser.password[1], credentials["password"] ) if not isLogged: return None data = UserCreateSchema().dump(storedUser) tokens = Auth.generate_session_token("USER", **data) except ValidationError as e: raise InvalidParametersError(e.data, e.messages, "Error occurred when trying to loggin user", e) return tokens
def test_check_hash_and_invalid_plain_password(self): invalid_password = "******" s_salt, s_password = Utils.hash_password(self.password) isCheck = Utils.verify_password(s_salt, s_password, invalid_password) self.assertFalse(isCheck)
def test_check_valid_hash_and_plain_password(self): s_salt, s_password = Utils.hash_password(self.password) isCheck = Utils.verify_password(s_salt, s_password, self.password) self.assertTrue(isCheck)