Skip to main content

Argon2PasswordHasher

Secure password hashing using the argon2 algorithm.

Attributes

AttributeTypeDescription
algorithmstring = "argon2"The unique identifier for the hashing algorithm used to prefix encoded password strings.
librarystring = "argon2"The name of the external Python library required to perform the argon2 hashing operations.
time_costinteger = 2The number of iterations used by the argon2 algorithm to increase the computation time required to hash a password.
memory_costinteger = 102400The amount of memory in kibibytes that the argon2 algorithm will utilize during the hashing process.
parallelisminteger = 8The number of parallel threads to be used by the argon2 algorithm during password hashing.

Methods


encode()

@classmethod
def encode(
password: string,
salt: string
) - > string

Generates a secure Argon2 hash string from a raw password and salt using the configured cost parameters.

Parameters

NameTypeDescription
passwordstringThe plain-text password to be hashed.
saltstringThe unique salt value used to protect against rainbow table attacks.

Returns

TypeDescription
stringThe complete encoded hash string prefixed with the algorithm identifier.

decode()

@classmethod
def decode(
encoded: string
) - > dict

Parses an encoded Argon2 hash string into its constituent components and configuration parameters.

Parameters

NameTypeDescription
encodedstringThe full encoded hash string to be decomposed.

Returns

TypeDescription
dictA dictionary containing the algorithm, hash, salt, and specific Argon2 cost parameters like memory_cost and parallelism.

verify()

@classmethod
def verify(
password: string,
encoded: string
) - > boolean

Validates a raw password against an existing encoded Argon2 hash.

Parameters

NameTypeDescription
passwordstringThe plain-text password to verify.
encodedstringThe stored hash string to validate against.

Returns

TypeDescription
booleanTrue if the password matches the hash, False otherwise.

safe_summary()

@classmethod
def safe_summary(
encoded: string
) - > dict

Provides a human-readable summary of the hashing parameters and masked versions of sensitive data.

Parameters

NameTypeDescription
encodedstringThe encoded hash string to summarize.

Returns

TypeDescription
dictA dictionary of descriptive labels and values suitable for administrative display.

must_update()

@classmethod
def must_update(
encoded: string
) - > boolean

Determines if an encoded hash should be re-hashed because the hasher's configuration or salt entropy requirements have changed.

Parameters

NameTypeDescription
encodedstringThe encoded hash string to evaluate for updates.

Returns

TypeDescription
booleanTrue if the hash parameters differ from current settings or if the salt is insufficient.

harden_runtime()

@classmethod
def harden_runtime(
password: string,
encoded: string
)

Placeholder method for runtime hardening; Argon2 does not implement a simple hardening algorithm due to its complexity.

Parameters

NameTypeDescription
passwordstringThe plain-text password.
encodedstringThe encoded hash string.

params()

@classmethod
def params() - > argon2.Parameters

Constructs an Argon2 parameters object using the current class settings for time, memory, and parallelism.

Returns

TypeDescription
argon2.ParametersAn object containing the specific Argon2 configuration used for hashing operations.