Password Strength

0.0.3.post2 · active · verified Thu Apr 16

The `password-strength` library (PyPI slug: `password-strength`, current version `0.0.3.post2`) provides tools for password strength assessment and validation. It allows defining a `PasswordPolicy` with various rules (e.g., minimum length, character types, entropy) to test if a password meets specified security requirements. The library also offers `PasswordStats` to get a normalized strength score and detailed analysis of a password. While the PyPI package itself was last updated in 2019, its GitHub repository shows more recent activity, suggesting ongoing relevance.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a password policy using `PasswordPolicy.from_names` and test a password against it. It also shows how to get detailed strength statistics, including entropy, complexity, and a normalized strength score using `PasswordStats`.

from password_strength import PasswordPolicy, PasswordStats

# Define a password policy
policy = PasswordPolicy.from_names(
    length=8,
    uppercase=1,
    numbers=1,
    special=1,
    nonletters=1
)

# Test a password against the policy
password = "StrongP@ssw0rd!"
errors = policy.test(password)

if not errors:
    print(f"Password '{password}' meets the policy requirements.")
else:
    print(f"Password '{password}' failed the following checks: {', '.join(errors)}")

# Get detailed strength statistics
stats = PasswordStats(password)
print(f"\nPassword entropy (bits): {stats.entropy_bits:.2f}")
print(f"Password complexity (0.00-0.99): {stats.complexity:.2f}")
print(f"Password strength (0.00-1.00): {stats.strength:.2f}")

view raw JSON →