Skip to content

auth

auth

Authentication for the web UI.

Uses session-based auth with login page and bcrypt password hashing. Credentials are set via environment variables.

hash_password(password: str) -> str

Hash a password using bcrypt.

verify_password(plain_password: str, hashed_password: str) -> bool

Verify a password against a bcrypt hash.

get_credentials_from_env() -> tuple[str | None, str | None]

Get username and hashed password from environment.

Set these environment variables: - THESEUS_WEB_USERNAME (e.g., "admin") - THESEUS_WEB_PASSWORD_HASH (bcrypt hash of the password)

Or for development, you can set: - THESEUS_WEB_PASSWORD (plain text - will be hashed automatically)

authenticate_user(username: str, password: str) -> bool

Authenticate a user with username and password.

Returns True if valid, False otherwise.

get_current_user(request: Request) -> str | None

Get the current logged-in user from session.

require_auth(request: Request) -> str

Dependency that requires authentication.

Raises HTTPException if not authenticated (handled by middleware). Returns username if authenticated.