Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Zozi96/hash-forge/llms.txt
Use this file to discover all available pages before exploring further.
PBKDF2Sha256Hasher and PBKDF2Sha1Hasher are password hashers built on Python’s stdlib hashlib.pbkdf2_hmac. They require no third-party packages, making them the lowest-friction option for environments where dependencies must be kept minimal. Both hashers produce a structured hash string that embeds the iteration count and salt, enabling safe round-trip verification and automatic detection of hashes that need rehashing as cost parameters are raised over time.
Import
PBKDF2Sha256Hasher
The primary PBKDF2 hasher. Uses SHA-256 as the underlying pseudorandom function.
Constructor
Number of PBKDF2 iterations. Higher values increase resistance to brute-force attacks at the cost of CPU time. Must be at least
150,000; raises InvalidHasherError if below this threshold.Number of random bytes used to generate the salt. The salt is hex-encoded before being embedded in the hash string.
Hash format
$. The <salt> is a hex-encoded random byte sequence and <hash> is the hex-encoded PBKDF2-derived key.
Methods
hash(string: str) -> str
Hashes the given password string. A fresh random salt is generated on every call, so two calls with the same input produce different output.
verify(string: str, hashed_string: str) -> bool
Verifies a plain-text string against a previously produced hashed_string. Re-derives the PBKDF2 key using the salt and iteration count stored in the hash, then compares using hmac.compare_digest to prevent timing attacks.
needs_rehash(hashed_string: str) -> bool
Returns True when the iteration count embedded in hashed_string differs from the iterations value the hasher was constructed with. Use this after a successful verify call to decide whether to re-hash and store a fresh hash at the new iteration count.
PBKDF2Sha1Hasher
A subclass of PBKDF2Sha256Hasher that replaces the SHA-256 digest with SHA-1. The constructor signature and hash-format structure are identical; only the embedded algorithm token changes.
Constructor
Number of PBKDF2 iterations. Same minimum and validation rules as
PBKDF2Sha256Hasher.Number of random bytes used to generate the salt.
