Skip to content

Hashing

hashing

Password hashing utilities using Argon2.

Provides secure password hashing and verification using the Argon2 algorithm, which is the winner of the Password Hashing Competition.

Functions

hash_password

hash_password(password: str) -> str

Hash a plaintext password using Argon2.

Source code in fastauth/core/hashing.py
def hash_password(password: str) -> str:
    """
    Hash a plaintext password using Argon2.
    """
    return _password_hasher.hash(password)

verify_password

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

Verify a plaintext password against a stored hash.

Returns False if hashed_password is None (OAuth-only users).

Source code in fastauth/core/hashing.py
def verify_password(hashed_password: str | None, plain_password: str) -> bool:
    """
    Verify a plaintext password against a stored hash.

    Returns False if hashed_password is None (OAuth-only users).
    """
    if hashed_password is None:
        return False
    try:
        return _password_hasher.verify(hashed_password, plain_password)
    except VerifyMismatchError:
        return False