def attempt_login(cls, username, password): user = UserService.get_user(username) if not user: return None hashed_pass = hash_password(password, user.salt) if hashed_pass != user.password: return None session = SessionService.get_session_by_user(user) if session: return session.token token = gen_token() SessionService.create_session(user, token) return token
def test_returns_token(self): token = gen_token() assert type(token) is str assert len(token) == 64