pwdlib is a modern password hashing library for Python, providing an easy-to-use wrapper to hash and verify passwords with secure algorithms like Argon2 and Bcrypt. It aims to be an alternative to `passlib`, which has seen reduced maintenance. The current version is 0.3.0, and it maintains an active development status, with updates released as needed.
pip install 'pwdlib[argon2]'Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the recommended password hashing configuration, hash a plain-text password, and then verify it. It also shows the `verify_and_update` method for automatic hash upgrades.
Upgrade your Python environment to version 3.10 or higher.
Update calls to `verify(password, hash)` and `verify_and_update(password, hash)`. For example, `password_hash.verify(old_hash, 'password')` should become `password_hash.verify('password', old_hash)`.Review `pwdlib`'s documentation for supported features and algorithms. If migrating from `passlib`, be aware of potential incompatibilities, especially with older hash formats or custom `CryptContext` configurations.
To use custom hashers, import them (e.g., `from pwdlib.hashers.bcrypt import BcryptHasher`) and instantiate `PasswordHash` explicitly: `password_hash = PasswordHash((BcryptHasher(),))`.
Install pwdlib with the recommended hashing algorithm support, for example: `pip install 'pwdlib[argon2]'` or `pip install 'pwdlib[bcrypt]'`.
Upgrade your `argon2-cffi` dependency to a compatible version, such as 23.1.0 or newer: `pip install --upgrade argon2-cffi`.
Ensure that the `PasswordHash` instance is configured to support the algorithm used to create the hash. Use `PasswordHash.recommended()` for common algorithms or explicitly pass a sequence of `HasherProtocol` objects: `from pwdlib.hashers.bcrypt import BcryptHasher; password_hash = PasswordHash((BcryptHasher(),))`.
Initialize `PasswordHash` either by using the recommended configuration or by explicitly providing a sequence of hasher objects: `password_hash = PasswordHash.recommended()` or `from pwdlib.hashers.argon2 import Argon2Hasher; password_hash = PasswordHash((Argon2Hasher(),))`.