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-strengthVerified import paths — ran on the pinned version, not inferred.
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`.
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.
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.
Define password requirements using `PasswordPolicy.from_names()` or by directly instantiating `PasswordPolicy` with desired rules, which is generally more readable and maintainable.
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.
Access validation methods on the `PasswordPolicy` object. For example, use `policy.test(password)` instead of `policy(password)`.
Use `PasswordPolicy` for testing against defined rules (`policy.test(password)`). Use `PasswordStats` to get raw metrics like entropy or complexity (`PasswordStats(password).strength`).
No dependency data recorded yet.