libpass: Comprehensive Password Hashing Framework

1.9.3 · active · verified Thu Apr 16

libpass is an actively maintained fork of the original `passlib` library, providing a comprehensive password hashing framework that supports over 30 schemes. It is currently at version 1.9.3 and receives regular updates to address compatibility issues, security concerns, and support newer Python versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `passlib.context.CryptContext` to hash and verify passwords using multiple schemes. It showcases how to configure the context and perform basic hashing and verification operations.

from passlib.context import CryptContext

# Configure a context with desired hashing schemes
# Common schemes include 'sha512_crypt', 'bcrypt', 'pbkdf2_sha256', 'argon2'
context = CryptContext(
    schemes=["sha512_crypt", "bcrypt", "pbkdf2_sha256", "argon2"],
    # For real applications, configure rounds/iterations for security and performance
    sha512_crypt__rounds=656000,
    bcrypt__rounds=12,
    pbkdf2_sha256__rounds=150000
)

password = "supersecretpassword"

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

# Verify a password against a hash
is_valid = context.verify(password, hashed_password)
print(f"Password valid: {is_valid}")

# Example with a wrong password
is_invalid = context.verify("wrongpassword", hashed_password)
print(f"Wrong password valid: {is_invalid}")

view raw JSON →