Skip to Content
oxcrypto

password-auth

Verify Argon2, PBKDF2 and scrypt records without knowing the scheme, and detect records that need rehashing.

from oxcrypto.password.password_auth import PASSWORD_AUTH

auth = PASSWORD_AUTH.PASSWORD_AUTH
encoded = auth.hash(b"example password")
if auth.verify(b"example password", encoded) and auth.needs_rehash(encoded):
    encoded = auth.hash(b"example password")
  • verify(password, encoded) reads the scheme from the PHC string and checks Argon2 ($argon2d$, $argon2i$, $argon2id$), PBKDF2 ($pbkdf2-sha256$, $pbkdf2-sha512$) and scrypt ($scrypt$) records. It returns False for a wrong password or another PHC scheme and raises ValueError for a string that is not a PHC string (for example a $5$ or $7$ crypt record).
  • needs_rehash(encoded) returns False only for Argon2id records with the crate's current recommendation (m=19456,t=2,p=1, the OWASP baseline). Every other scheme or cost returns True, including records from ARGON2.ARGON2ID.hash() with its higher-cost defaults.
  • hash(password) creates a record with that recommendation, so a freshly hashed record never needs rehashing.

Records with an Argon2 secret cannot be verified here; use ARGON2.verify(..., secret=...).

The implementation is the RustCrypto password-auth crate 2.0.0 (MSRV 1.85), a stable release with no published audit, built on argon2 0.6, pbkdf2 0.13 and scrypt 0.12. The schemes are specified in RFC 9106, RFC 8018 and RFC 7914. Tests use the Argon2 reference implementation's PHC strings and records from the scheme-specific selectors.