Skip to content

authentication

mlte/backend/api/auth/authentication.py

Authentication handling.

authenticate_user(username, password, user_store_session)

Validates the credentials.

Source code in mlte/backend/api/auth/authentication.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def authenticate_user(
    username: str, password: str, user_store_session: UserStoreSession
) -> bool:
    """Validates the credentials."""
    user = None
    try:
        user = user_store_session.user_mapper.read(username)
    except Exception as ex:
        # Assume any exception means we couldn't load user it.
        logging.error(
            f"Error reading user; type is: {ex.__class__.__name__}, error is: {ex}"
        )
        return False
    if not passwords.verify_password(password, user.hashed_password):
        # print(f"Could not verify password <{password}> vs hashed <{user.hashed_password}>")
        return False
    else:
        return True