passwordlib-py
utility library to verify, hash, compare and more for passwords
Installation
Just run pip install password-library
Algorithms
List of supported algorithms
| Algorythm | Comment |
|---|---|
| sha1 | |
| sha224 | |
| sha256 | |
| sha384 | |
| sha512 | |
| sha3_224 | |
| sha3_256 | |
| sha3_384 | |
| sha3_512 | |
| shake_128 | |
| shake_256 | |
| blake2b | Not Tested |
| blake2s | Not Tested |
| md5 |
Example usage
passwordlib offers an easy interface to create password-hashes
from passwordlib import util as pwutil
hashed = pwutil.hash_password("my_secret")
print(pwutil.compare_password("your_secret", hashed)) # False
print(pwutil.compare_password("my_secret", hashed)) # True
print(pwutil.extract_algorythm(hashed)) # sha256
print(pwutil.extract_iterations(hashed)) # 100_000
print(pwutil.extract_salt(hashed)) # b'...'
print(pwutil.extract_hashed(hashed)) # b'...'
you can also configure the algorithms or number of iterations
from passwordlib import util as pwutil, config as pwconfig
# either globally
pwconfig.DEFAULT_ALGORITHM = "md5"
pwconfig.DEFAULT_ITERATIONS = 1_000_000
pwconfig.DEFAULT_SALT_LENGTH = 64
# or per instance
pwutil.hash_password(
password='password',
algorithm="md5", iterations=1_000_000, salt_length=64,
)
it also offers the PasswordAttribute class to automatically hash attributes on objects
from passwordlib.attr import PasswordAttribute
class User:
name: str
password = PasswordAttribute()
user = User()
print(user.password) # None
user.password = "secret"
print(user.password) # b'\x06sha256\x00\x01\x86\xa0\x00 \x07\xcfg\x0ec\xa6D\xea\xae\x03S\xa1\xfcz\xaew\x02\x8b\xf1\xe5\xaf\x83n&\x87'\xcdRi!\xd9\xe7\x00@qV\xd3\x81\x113:*"\x05\xba\x12Xb\x04\xeb\x08Sn\x08Z\x9f\x89\xa50~\xa0\xb4\xbd.\xc6\x18"\xf9l\xeds\xbc\xc2B\xa7\xef\xa1\x8a\x7f3\xc1u\x17d\xce\xf2\x98+l\x86\xb7\x1c\xb4\xf0\x07t8\xc9'
you can also check if a password is commonly used
from passwordlib.commonly_used import is_commonly_used
print(is_commonly_used("password")) # True
print(is_commonly_used("123456")) # True
print(is_commonly_used("matrix")) # True
print(is_commonly_used("password-library")) # False
print(is_commonly_used("TifnedjothUj")) # False
and be able to validate a password against different criteria to ensure a password is safe.
from passwordlib.analyzer import Analyzer
# may not seem safe at first, but think:
# 9 digits,lowercase and symbols, not commonly used and no repeating characters
result = Analyzer("my_secret")
print(result.is_secure) # True
print(result.is_highly_secure) # False
print(result.score) # 5
print(result.contains_lowercase) # True
print(result.contains_uppercase) # False
print(result.contains_digits) # False
print(result.contains_symbols) # True
print(result.length) # 9
print(result.max_consecutive_character) # 1
print(result.is_commonly_used) # False
# you can do such a check here:
number_of_security_features = sum((
result.contains_lowercase,
result.contains_uppercase,
result.contains_digits,
result.contains_symbols,
result.length >= 8,
result.charset_length > (result.length // 2)
))
if number_of_security_features < 5 or result.is_commonly_used:
raise PasswordTooWeakError(result.password)
# here are more examples for you
r = Analyzer("password")
print(r.score, r.is_secure, r.is_highly_secure)
# 0 False False
r = Analyzer("123456")
print(r.score, r.is_secure, r.is_highly_secure)
# 0 False False
r = Analyzer("matrix")
print(r.score, r.is_secure, r.is_highly_secure)
# 0 False False
r = Analyzer("password-library")
print(r.score, r.is_secure, r.is_highly_secure)
# 7 True False
r = Analyzer("TifnedjothUj")
print(r.score, r.is_secure, r.is_highly_secure)
# 6 True False
r = Analyzer("passwoooooooooooooord")
print(r.score, r.is_secure, r.is_highly_secure)
# 1 False False
Roadmap
- passwordlib
- passwordlib.util
- def hashing
- def comparing
- def dumping
- def loading
- passwordlib.attr
- class PasswordAttribute
- passwordlib.commonly_used
- def is_common_password
- passwordlib.Analyzer
- class Analyzer
- passwordlib.validator
- class PasswordValidator
- passwordlib.validator.rules
- passwordlib.util
- Documentation
Metadata
Release files for password-library 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| password_library-0.4.2.tar.gz | 385.2 kB | Without provenance | Details for password_library-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| password_library-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for password_library-0.4.2-py3-none-any.whl |
Total release size: 771.1 kB
Release files / password_library-0.4.2.tar.gz
| Download URL | password_library-0.4.2.tar.gz |
|---|---|
| Size | 385.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14230d79ca751e61c1a58839538635a1dd5c5af9b2c3f2c1cf9695002e67bb36
|
|
BLAKE2b-256 checksum How to use checksums |
8ffb32f5c5d31c09d24fed1ab239c6d8eebc1b6dd3de1ba47662bc207423a284
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.12
|
Release files / password_library-0.4.2-py3-none-any.whl
| Download URL | password_library-0.4.2-py3-none-any.whl |
|---|---|
| Size | 385.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d20ef64b60b2fae8de6cfb47c1da4c46442a0da711a02a95965dfe33ab4b179
|
|
BLAKE2b-256 checksum How to use checksums |
9f313e8fe15170c21268d479cf043236b34f9b61b1238df5219b0e8fddf5068f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.12
|
Security for password-library 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.