pwdlib: Modern Password Hashing for Python

0.3.0 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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.

from pwdlib import PasswordHash

# Get a PasswordHash instance with recommended hashers (currently Argon2)
password_hash = PasswordHash.recommended()

# Hash a password
hashed_password = password_hash.hash("mysecretpassword")
print(f"Hashed password: {hashed_password}")

# Verify a password
is_valid = password_hash.verify("mysecretpassword", hashed_password)
print(f"Password is valid: {is_valid}")

# Verify and update (if hasher or hash needs upgrade)
is_valid_and_updated, new_hash = password_hash.verify_and_update("mysecretpassword", hashed_password)
print(f"Password valid and potentially updated: {is_valid_and_updated}, New hash: {new_hash}")

view raw JSON →