Production-quality, cybersecurity-focused Python toolkit for generating secure passwords and passphrases with comprehensive security analysis, password auditing, and encrypted vault functionality.
This project is built with security as the primary concern:
- CSPRNG Only: Uses Python's
secretsmodule (cryptographically secure) - NEVERrandom - Memory-Hard KDFs: Argon2id, bcrypt, scrypt for password hashing
- Authenticated Encryption: Fernet (AES-128-CBC + HMAC-SHA256) for vault
- Constant-Time Operations: Prevents timing attacks in verification
- No Sensitive Data Logging: Built-in secure logging system
- Input Validation: All user inputs are validated
- Features
- Architecture
- Installation
- Quick Start
- CLI Usage
- API Usage
- Cryptographic Details
- Security Considerations
- Contributing
- License
-
Secure Password Generation
- Cryptographically secure random generation
- Customizable length and character classes
- Exclude ambiguous characters option
- Entropy calculation
-
Diceware-Style Passphrases
- Uses EFF large wordlist (7776 words)
- Configurable word count and separators
- Optional capitalization and numbers
- High entropy for memorability
-
Password Strength Auditing
- Entropy evaluation
- Character class diversity analysis
- Pattern detection (sequences, repeats, keyboard patterns)
- Dictionary word detection
- Security score (0-100) and recommendations
-
Secure Password Hashing
- Argon2id (PHC winner - recommended)
- bcrypt (industry standard)
- scrypt (memory-hard alternative)
- Verification with constant-time comparison
-
Encrypted Password Vault
- Master password protected
- Fernet authenticated encryption
- PBKDF2-HMAC-SHA256 key derivation
- Export and import capabilities
-
Entropy Analysis
- Bit-level entropy calculation
- Strength classification
- Crack time estimation
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLI Interface β
β (Click-based) β
ββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββ βββββββββββ ββββββββ
βPassword β βPassphraseβ βAudit β
βGeneratorβ βGenerator β βSystemβ
ββββββ¬βββββ ββββββ¬ββββββ ββββ¬ββββ
β β β
ββββββββββ¬ββββ΄βββββββββββββ
β
βΌ
βββββββββββββββββ
β Entropy β
β Calculator β
βββββββββββββββββ
β
βββββββββββΌββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββ ββββββββ ββββββββββββ
βArgon2idβ βbcryptβ βVault β
βHasher β βHasherβ β(Fernet) β
ββββββββββ ββββββββ ββββββββββββ
β
βΌ
βββββββββββββββββ
β Secure Logger β
βββββββββββββββββ
# Clone repository
git clone https://github.com/Kagias/secure-password-generator.git
cd secure-password-generator
# IMPORTANT: Install the real EFF wordlist for production use
# The included wordlist is a placeholder for development only
curl -o wordlists/temp.txt https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt
cut -f2 wordlists/temp.txt > wordlists/eff_large_wordlist.txt
rm wordlists/temp.txt
# Or see wordlists/README.md for alternative installation methods
# Install with pip (editable mode)
pip install -e .
# Or install with development dependencies
pip install -e ".[dev]"Core dependencies:
click>=8.1.0- CLI frameworkcryptography>=41.0.0- Fernet encryptionargon2-cffi>=23.1.0- Argon2 hashingbcrypt>=4.0.0- bcrypt hashing
# Generate a secure password
passwordgen generate
# Generate a passphrase
passwordgen passphrase
# Audit password strength
passwordgen audit "MyP@ssw0rd"
# Create encrypted vault
passwordgen vault init myvault.vaultfrom passwordgen import PasswordGenerator, PassphraseGenerator
# Generate password
gen = PasswordGenerator(length=16, symbols=True)
password = gen.generate()
print(f"Password: {password}")
print(f"Entropy: {gen.entropy_bits:.1f} bits")
# Generate passphrase
passgen = PassphraseGenerator(word_count=6)
passphrase = passgen.generate()
print(f"Passphrase: {passphrase}")
print(f"Entropy: {passgen.entropy_bits:.1f} bits")# Basic password (default: 16 characters)
passwordgen generate
# Custom length
passwordgen generate --length 24
# Without symbols
passwordgen generate --no-symbols
# Exclude ambiguous characters (0, O, 1, l, I)
passwordgen generate --exclude-ambiguous
# Generate multiple passwords
passwordgen generate --count 5
# Show entropy information
passwordgen generate --show-entropy# Basic passphrase (default: 6 words)
passwordgen passphrase
# Custom word count
passwordgen passphrase --words 8
# Custom separator
passwordgen passphrase --separator "_"
# Capitalize words
passwordgen passphrase --capitalize
# Include random number
passwordgen passphrase --include-number
# Show entropy
passwordgen passphrase --show-entropy# Audit a password
passwordgen audit "MyPassword123!"
# Output includes:
# - Strength rating (Very Weak to Very Strong)
# - Entropy in bits
# - Security score (0-100)
# - Character class analysis
# - Detected issues
# - Recommendations# Hash with Argon2id (recommended)
passwordgen hash "mypassword"
# Hash with bcrypt
passwordgen hash "mypassword" --algorithm bcrypt
# Hash with scrypt
passwordgen hash "mypassword" --algorithm scrypt
# Verify password
passwordgen verify "mypassword" "$argon2id$..."# Initialize new vault
passwordgen vault init myvault.vault
# Add entry
passwordgen vault add myvault.vault gmail
# Add with generated password
passwordgen vault add myvault.vault github --generate
# List entries
passwordgen vault list myvault.vault
# Get entry
passwordgen vault get myvault.vault gmail
# Delete entry
passwordgen vault delete myvault.vault gmailfrom passwordgen import PasswordGenerator
# Create generator with custom settings
gen = PasswordGenerator(
length=20,
uppercase=True,
lowercase=True,
digits=True,
symbols=True,
exclude_ambiguous=True
)
# Generate passwords
password = gen.generate()
passwords = gen.generate_multiple(10)
# Access properties
print(f"Charset size: {len(gen.charset)}")
print(f"Entropy: {gen.entropy_bits:.2f} bits")from passwordgen import PassphraseGenerator
# Create generator
gen = PassphraseGenerator(
word_count=6,
separator="-",
capitalize=True,
include_number=True
)
# Generate passphrases
passphrase = gen.generate()
passphrases = gen.generate_multiple(5)
# Access properties
print(f"Wordlist size: {gen.wordlist_size}")
print(f"Entropy: {gen.entropy_bits:.2f} bits")from passwordgen.entropy import (
calculate_password_entropy,
calculate_passphrase_entropy,
entropy_to_strength,
estimate_crack_time
)
# Calculate entropy
entropy = calculate_password_entropy("MyP@ssw0rd!")
print(f"Entropy: {entropy:.2f} bits")
# Get strength rating
strength = entropy_to_strength(entropy)
print(f"Strength: {strength}")
# Estimate crack time
time_str = estimate_crack_time(entropy)
print(f"Estimated crack time: {time_str}")from passwordgen import PasswordAuditor
auditor = PasswordAuditor()
result = auditor.audit("MyP@ssw0rd!")
print(f"Strength: {result.strength}")
print(f"Score: {result.score}/100")
print(f"Entropy: {result.entropy_bits:.2f} bits")
for issue in result.issues:
print(f"Issue: {issue}")
for rec in result.recommendations:
print(f"Recommendation: {rec}")from passwordgen import SecureHasher
hasher = SecureHasher()
# Hash passwords
argon2_hash = hasher.hash_argon2("mypassword")
bcrypt_hash = hasher.hash_bcrypt("mypassword")
scrypt_hash = hasher.hash_scrypt("mypassword")
# Verify passwords
is_valid = hasher.verify_argon2("mypassword", argon2_hash)
print(f"Valid: {is_valid}")from passwordgen import SecureVault
from pathlib import Path
# Create vault
vault = SecureVault(Path("myvault.vault"), "master_password")
# Add entries
vault.add_entry("gmail", "mypassword123",
metadata={"email": "user@gmail.com"})
# Get entry
entry = vault.get_entry("gmail")
print(f"Password: {entry['password']}")
# List entries
entries = vault.list_entries()
# Delete entry
vault.delete_entry("gmail")
# Change master password
vault.change_master_password("new_master_password")
# Export vault
vault.export_encrypted(Path("backup.vault"))All password and passphrase generation uses Python's secrets module, which provides:
- Access to the OS's cryptographically secure random number generator
secrets.choice()for selection from character sets/wordlistssecrets.randbelow()for bounded integer generation- Suitable for security-sensitive applications (unlike
randommodule)
Password Entropy:
entropy = length Γ logβ(charset_size)
Example: 16-char password with 94 characters
entropy = 16 Γ logβ(94) β 105.1 bits
Passphrase Entropy:
entropy = word_count Γ logβ(wordlist_size)
Example: 6 words from EFF list (7776 words)
entropy = 6 Γ logβ(7776) β 77.5 bits
- Winner of Password Hashing Competition (PHC)
- Type: Memory-hard key derivation function
- Parameters:
- Time cost: 3 iterations (default)
- Memory cost: 64 MiB (default)
- Parallelism: 4 threads (default)
- Benefits: Best resistance to GPU/ASIC attacks
- Industry Standard since 1999
- Type: Blowfish-based key derivation
- Parameters: Cost factor 12 (default) = 2ΒΉΒ² = 4096 iterations
- Benefits: Battle-tested, widely supported
- Limitation: 72-byte password maximum
- Type: Memory-hard key derivation function
- Parameters:
- N: 2ΒΉβ΄ = 16384 (CPU/memory cost)
- r: 8 (block size)
- p: 1 (parallelization)
- Memory usage: 128 Γ N Γ r = 16 MiB
- Benefits: High memory requirement deters hardware attacks
Fernet provides:
- AES-128 encryption in CBC mode
- HMAC-SHA256 for authentication
- Timestamp for expiration support
- Safe against padding oracle attacks
Key Derivation:
- Algorithm: PBKDF2-HMAC-SHA256
- Iterations: 480,000 (OWASP 2023 recommendation)
- Salt: 16 bytes (randomly generated per vault)
- Output: 32 bytes (256 bits)
Protected Against:
- Brute-force attacks (high entropy)
- Dictionary attacks (pattern detection, Diceware)
- Rainbow tables (unique salts per hash)
- Timing attacks (constant-time comparisons)
- Weak randomness (CSPRNG only)
- GPU/ASIC attacks (memory-hard KDFs)
NOT Protected Against:
- Keyloggers or screen capture
- Memory dumps of running processes
- Physical access to unlocked systems
- Compromised operating systems
- Side-channel attacks on hardware
- Password Storage: Always hash passwords before storage
- Master Passwords: Use passphrases (easier to remember, high entropy)
- Vault Files: Keep encrypted vaults on encrypted storage
- Regular Updates: Rotate passwords periodically
- Unique Passwords: Never reuse passwords across services
Attempts per second: 10-100
Minimum entropy: 28 bits (hours to crack)
Recommended: 40+ bits (years to crack)
GPU cluster: ~1e12 guesses/second
Minimum entropy: 60 bits (decades to crack)
Recommended: 80+ bits (centuries to crack)
For same entropy:
- Password: Harder to remember, shorter
- Passphrase: Easier to remember, longer
Example:
Tr!0k#mP2$sQ(random) β 77 bitscorrect-horse-battery-staple-lamp-river(6 words) β 77 bits
# Install development dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run with coverage
pytest --cov=passwordgen --cov-report=html
# Run specific test file
pytest tests/test_password.py -v# Format code
black src/ tests/
# Type checking
mypy src/
# Security scanning
bandit -r src/secure-password-generator/
βββ src/passwordgen/ # Main package
β βββ __init__.py # Package exports
β βββ password.py # Password generator
β βββ passphrase.py # Passphrase generator
β βββ entropy.py # Entropy calculations
β βββ audit.py # Password auditor
β βββ crypto.py # Hashing & verification
β βββ vault.py # Encrypted vault
β βββ logging_secure.py # Secure logging
β βββ cli.py # CLI interface
βββ tests/ # Test suite
βββ wordlists/ # EFF wordlist
βββ docs/ # Documentation
βββ pyproject.toml # Package configuration
βββ README.md # This file
- API Reference: See
docs/api_reference.md - Security Guide: See
docs/index.md - Contributing: See
CONTRIBUTING.md
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Run security scanning with Bandit
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- EFF for the large wordlist used in passphrase generation
- Password Hashing Competition for Argon2
- OWASP for security guidelines and best practices
- cryptography.io for excellent Python cryptography library
Author: Kagias
Remember: A strong password is your first line of defense. Use this tool to generate secure, unique passwords for all your accounts!