MD5PasswordHasher
The Salted MD5 password hashing algorithm (not recommended)
Attributes
| Attribute | Type | Description |
|---|---|---|
| algorithm | string = "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
| Name | Type | Description |
|---|---|---|
| password | string | The plain-text password to be hashed. |
| salt | string | A unique string used to seed the hashing process to prevent rainbow table attacks. |
Returns
| Type | Description |
|---|---|
string | A 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
| Name | Type | Description |
|---|---|---|
| encoded | string | The full salted hash string retrieved from storage. |
Returns
| Type | Description |
|---|---|
object | A 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
| Name | Type | Description |
|---|---|---|
| password | string | The plain-text password provided by the user for authentication. |
| encoded | string | The previously stored salted hash string to verify against. |
Returns
| Type | Description |
|---|---|
boolean | True 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
| Name | Type | Description |
|---|---|---|
| encoded | string | The salted hash string to summarize. |
Returns
| Type | Description |
|---|---|
object | A 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
| Name | Type | Description |
|---|---|---|
| encoded | string | The salted hash string to evaluate for update requirements. |
Returns
| Type | Description |
|---|---|
boolean | True 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
| Name | Type | Description |
|---|---|---|
| password | string | The plain-text password. |
| encoded | string | The salted hash string. |