Skip to main content

MD5PasswordHasher

The Salted MD5 password hashing algorithm (not recommended)

Attributes

AttributeTypeDescription
algorithmstring = "md5"Identifier for the hashing algorithm used to encode and decode passwords.

Methods


encode()

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

Encodes a plain-text password into a salted MD5 hash string for secure storage.

Parameters

NameTypeDescription
passwordstringThe plain-text password to be hashed.
saltstringA unique string used to seed the hashing process to prevent rainbow table attacks.

Returns

TypeDescription
stringA formatted string containing the algorithm name, the salt, and the resulting MD5 hex digest separated by dollar signs.

decode()

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

Parses an encoded password string into its constituent components.

Parameters

NameTypeDescription
encodedstringThe full salted hash string retrieved from storage.

Returns

TypeDescription
objectA dictionary containing the algorithm name, the salt, and the raw hash digest.

verify()

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

Validates a plain-text password against a stored salted MD5 hash using a constant-time comparison.

Parameters

NameTypeDescription
passwordstringThe plain-text password provided by the user for authentication.
encodedstringThe previously stored salted hash string to verify against.

Returns

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

safe_summary()

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

Generates a summary of the hashing metadata with sensitive information masked for logging or display.

Parameters

NameTypeDescription
encodedstringThe salted hash string to summarize.

Returns

TypeDescription
objectA dictionary containing the algorithm name and masked versions of the salt and hash.

must_update()

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

Determines if the stored hash needs to be re-encoded based on the entropy of the salt.

Parameters

NameTypeDescription
encodedstringThe salted hash string to evaluate for update requirements.

Returns

TypeDescription
booleanTrue if the salt entropy is insufficient and the password should be re-hashed, False otherwise.

harden_runtime()

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

Performs no-op operations to satisfy the interface; MD5 does not support runtime hardening like work factor adjustments.

Parameters

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