Home / Function/ get_current_username() — fastapi Function Reference

get_current_username() — fastapi Function Reference

Architecture documentation for the get_current_username() function in tutorial007_an_py39.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  108483a9_d298_00c0_2ab7_6b3487b061c1["get_current_username()"]
  a3de186a_b6a5_46b3_f084_3661a4356671["tutorial007_an_py39.py"]
  108483a9_d298_00c0_2ab7_6b3487b061c1 -->|defined in| a3de186a_b6a5_46b3_f084_3661a4356671
  style 108483a9_d298_00c0_2ab7_6b3487b061c1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

docs_src/security/tutorial007_an_py39.py lines 12–31

def get_current_username(
    credentials: Annotated[HTTPBasicCredentials, Depends(security)],
):
    current_username_bytes = credentials.username.encode("utf8")
    correct_username_bytes = b"stanleyjobson"
    is_correct_username = secrets.compare_digest(
        current_username_bytes, correct_username_bytes
    )
    current_password_bytes = credentials.password.encode("utf8")
    correct_password_bytes = b"swordfish"
    is_correct_password = secrets.compare_digest(
        current_password_bytes, correct_password_bytes
    )
    if not (is_correct_username and is_correct_password):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Incorrect username or password",
            headers={"WWW-Authenticate": "Basic"},
        )
    return credentials.username

Domain

Subdomains

Frequently Asked Questions

What does get_current_username() do?
get_current_username() is a function in the fastapi codebase, defined in docs_src/security/tutorial007_an_py39.py.
Where is get_current_username() defined?
get_current_username() is defined in docs_src/security/tutorial007_an_py39.py at line 12.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free