Registry / auth-security / password-strength

password-strength

JSON →
library0.0.3.post2pypypi✓ verified 86d ago

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.

pip install password-strength
INSTALL
IMPORT
SIG · PASSWORD-STRENGTH
P
password-strength
auth-securitypythonv0.0.3.post2
Install
1.6s avg
Import
13ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.3.post2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.013s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PasswordPolicy
from password_strength import PasswordPolicy
PasswordStats
from password_strength import PasswordStats

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}")
Debug
Known issues
gotchaThe default entropy calculation might be less intuitive for users than a complexity score or explicit policy checks. While `entropy_bits` is a fundamental measure, `complexity` (0.00-0.99) or `strength` (0.00-1.00) are often more digestible for direct user feedback.
fix
Prefer using `policy.test()` to get a list of failed rules or `PasswordStats().complexity` / `PasswordStats().strength` for a more user-friendly score, especially when providing feedback to end-users.
affects: <=0.0.3.post2
gotchaA password might pass basic length and character type rules but still contain easily guessable repetitions (e.g., 'aaaaaa', '123123'). The library's `Policy` object doesn't inherently check for overly repetitive patterns beyond what the entropy calculation might implicitly catch.
fix
For enhanced security, consider adding custom checks for known weak patterns, dictionary words, or sequential characters, potentially by extending the `PasswordPolicy` or implementing separate validation functions. The library offers the flexibility to define custom validation rules or combine with other techniques.
affects: <=0.0.3.post2
deprecatedDirect manipulation or reliance on `weak_bits`, `medium_bits`, `strong_bits` constants might be less recommended than using the `Policy` object's named rules, as policies provide a clearer, more configurable approach to defining acceptable passwords.
fix
Define password requirements using `PasswordPolicy.from_names()` or by directly instantiating `PasswordPolicy` with desired rules, which is generally more readable and maintainable.
affects: <=0.0.3.post2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'password_strength'
The library is not installed or the Python environment is incorrect.
fix
Ensure the library is installed in your current environment using `pip install password-strength`. If using virtual environments, activate the correct one before running your script.
TypeError: 'PasswordPolicy' object is not callable
Attempting to call a `PasswordPolicy` object like a function instead of using its `test()` method.
fix
Access validation methods on the `PasswordPolicy` object. For example, use `policy.test(password)` instead of `policy(password)`.
AttributeError: 'PasswordStats' object has no attribute 'test'
Confusing `PasswordStats` (for analysis) with `PasswordPolicy` (for validation). `PasswordStats` provides statistical properties, not policy testing.
fix
Use `PasswordPolicy` for testing against defined rules (`policy.test(password)`). Use `PasswordStats` to get raw metrics like entropy or complexity (`PasswordStats(password).strength`).
Upgrade
Version history
0.0.3.post2latest on PyPI · released Jan 4, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
password-strength — pip install password-strength · libregistry