All-in-one Python authentication toolkit: password validation, password hashing, email validation.
Project description
python-auth-toolkit
An all-in-one, highly secure, and configurable Python authentication toolkit. It provides robust password strength validation, secure password hashing (Bcrypt & Argon2), and custom validation error feedback.
Features
- Password Validator: Fully customizable rules (minimum/maximum length, uppercase/lowercase requirements, digit requirements, and special character requirements).
- Common Passwords Protection: Built-in protection to block the most common easily guessable passwords (e.g., "123456", "password", "qwerty").
- Password Hasher: Secure password hashing supporting Bcrypt and Argon2id with timing-safe verification.
- Upgrades & Re-hashing: Easy checking for out-of-date password hashes (e.g., when cost factors are increased) to allow seamless re-hashing.
- Type Safety: Full PEP 561 type annotation support.
Installation
Install using pip:
pip install python-auth-toolkit
Quick Start
1. Password Hashing
from python_auth_toolkit import PasswordHasher
# Initialize with default settings (Bcrypt with 12 rounds)
hasher = PasswordHasher()
# Hash a password
hashed = hasher.hash("my_secure_password")
print(hashed) # Output: $2b$12$... (embedded salt and rounds)
# Verify a password
is_match = hasher.verify("my_secure_password", hashed)
print(is_match) # True
# Check if a hash needs to be regenerated (e.g., after increasing security defaults)
upgraded_hasher = PasswordHasher(rounds=14)
if upgraded_hasher.needs_rehash(hashed):
new_hash = upgraded_hasher.hash("my_secure_password")
Using Argon2:
from python_auth_toolkit import PasswordHasher
# Initialize with Argon2id
hasher = PasswordHasher(algorithm="argon2", time_cost=3, memory_cost=65536)
# Hash and verify
hashed = hasher.hash("another_password")
is_match = hasher.verify("another_password", hashed)
2. Password Strength Validation
from python_auth_toolkit import PasswordValidator
# Initialize validator with custom rules
validator = PasswordValidator(
min_length=10,
required_uppercase=True,
required_lowercase=True,
required_digits=True,
required_special=True,
block_common_passwords=True
)
# Validate a password
result = validator.validate("P@ssw0rd123")
if result.is_valid:
print(f"Valid! Strength Score: {result.strength_score}/100")
else:
print("Invalid Password. Errors:")
for error in result.errors:
print(f" - {error}")
Configuration Options
PasswordValidator parameters:
min_length(int, default: 8): Minimum length required.max_length(int, default: 128): Maximum length allowed.required_uppercase(bool, default: True): Require at least one uppercase letter.required_lowercase(bool, default: True): Require at least one lowercase letter.required_digits(bool, default: True): Require at least one digit.required_special(bool, default: True): Require at least one special character.block_common_passwords(bool, default: True): Reject passwords present in the common passwords list.
PasswordHasher parameters:
algorithm(str, default: 'bcrypt'): Choose between'bcrypt'or'argon2'.rounds(int, default: 12): Cost factor rounds for Bcrypt.time_cost(int, default: 3): Time cost for Argon2.memory_cost(int, default: 65536): Memory cost in KiB for Argon2.parallelism(int, default: 4): Parallelism factor threads for Argon2.
Requirements
- Python >= 3.9
- bcrypt >= 4.0
- argon2-cffi >= 21.3
- email-validator >= 2.0
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_auth_toolkit-0.1.0.tar.gz.
File metadata
- Download URL: python_auth_toolkit-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c063b1e6b8052780fdc7f802c901f76ad45c39dbe15f793b720a5f011b1e480a
|
|
| MD5 |
ffcbb692ec3b5405e6ec8f14fd1ef7fb
|
|
| BLAKE2b-256 |
ec4454b3cc4758b6936886296fc7748df95a63ff8f0c66e1e8d0d2e3eadc5c27
|
File details
Details for the file python_auth_toolkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_auth_toolkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfce012107fd8a05c14d99043f2c3e080e18cf03f6b69e6598731257065fbdca
|
|
| MD5 |
d20d261725047e325883ff94819effc8
|
|
| BLAKE2b-256 |
f02843ef3407e55a18f7f6215f582b130930ab5e6e167488136364791df01f44
|