Home / Function/ get_current_username() — fastapi Function Reference

get_current_username() — fastapi Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  1bd9ab38_0f80_b30a_3324_7acc77da2fa7["get_current_username()"]
  6f1b737b_b9f8_4d44_684d_41ca4b921191["tutorial007_py39.py"]
  1bd9ab38_0f80_b30a_3324_7acc77da2fa7 -->|defined in| 6f1b737b_b9f8_4d44_684d_41ca4b921191
  style 1bd9ab38_0f80_b30a_3324_7acc77da2fa7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

docs_src/security/tutorial007_py39.py lines 11–28

def get_current_username(credentials: 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_py39.py.
Where is get_current_username() defined?
get_current_username() is defined in docs_src/security/tutorial007_py39.py at line 11.

Analyze Your Own Codebase

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

Try Supermodel Free