| Crates.io | password_policy |
| lib.rs | password_policy |
| version | 0.1.0 |
| created_at | 2025-07-31 20:15:49.55224+00 |
| updated_at | 2025-07-31 20:15:49.55224+00 |
| description | A comprehensive password generator and strength analyzer with configurable policies |
| homepage | |
| repository | https://github.com/Yemidatadev/password_policy/tree/main |
| max_upload_size | |
| id | 1775665 |
| size | 58,848 |
A comprehensive Rust library for password generation and strength analysis with configurable security policies.
Add this to your Cargo.toml:
[dependencies]
password_policy = "0.1.0"
# Generate 1 corporate policy password
cargo run -- generate
# Generate 5 high-security passwords
cargo run -- generate -c 5 -p high-security
# Generate 3 passwords with analysis
cargo run -- generate -c 3 -a
# Analyze a password with corporate policy
cargo run -- analyze "MyP@ssw0rd123"
# Analyze with high-security policy
cargo run -- analyze "X7\$kL9@nQ2&mP5!wR8#tU3*vY6+" -p high-security
# Show corporate policy requirements
cargo run -- requirements
# Show high-security policy requirements
cargo run -- requirements -p high-security
use password_policy::{CorporatePolicy, HighSecurityPolicy, PasswordPolicy, PasswordManager};
// Using individual policies
let corporate_policy = CorporatePolicy::default();
let password = corporate_policy.generate();
let analysis = corporate_policy.analyze_strength(&password);
// Using the password manager
let manager = PasswordManager::new();
let passwords = manager.generate_batch(5, Some("corporate"));
let analyses = manager.analyze_batch(&passwords, Some("corporate"));
Best for: Business environments, general secure applications
Default Requirements:
Best for: Sensitive systems, high-value accounts
Default Requirements:
cargo run -- generate [OPTIONS]
Options:
-c, --count <COUNT> Number of passwords to generate [default: 1]
-p, --policy <POLICY> Policy to use (corporate, high-security) [default: corporate]
-a, --analyze Show analysis for generated passwords
-h, --help Print help
# Basic generation
cargo run -- generate
# Generate multiple passwords
cargo run -- generate -c 5
# Generate with different policy
cargo run -- generate -p high-security
# Generate with immediate analysis
cargo run -- generate -c 3 -a -p corporate
cargo run -- analyze <PASSWORD> [OPTIONS]
Arguments:
<PASSWORD> Password to analyze (use quotes for spaces/symbols)
Options:
-p, --policy <POLICY> Policy to use for analysis [default: corporate]
-h, --help Print help
# Basic analysis
cargo run -- analyze "password123"
# Analysis with different policy
cargo run -- analyze "MySecureP@ssw0rd2024!" -p high-security
# Complex password with special characters
cargo run -- analyze "Tr0ub4dor&3#MyL0ng\$ecureP@ss" -p corporate
cargo run -- requirements [OPTIONS]
Options:
-p, --policy <POLICY> Policy name to show requirements for [default: corporate]
-h, --help Print help
# Show corporate requirements
cargo run -- requirements
# Show high-security requirements
cargo run -- requirements -p high-security
The tool provides comprehensive analysis including:
Strength Scoring Factors
🔐 Generating 3 password(s) with corporate policy:
1. K9#mL2@pQ5&wR8!tU
2. N7$vB4@xC6*zA3#eY
3. P2&qM8@jL5#kN9!sW
🔒 High-Security Policy Passwords:
1. X7$kL9@nQ2&mP5!wR8#tU3*vY6+
2. B4#zC9@mK6&qP2!xL5*sW8+nR7$
3. F3&jM8@vN5#kQ9!tL2*pW6+rY4$
📊 Analyzing password strength with corporate policy:
Password: MyP@ssw0rd!2024
Strength: Good (Score: 72)
Entropy: 67.8 bits
Time to crack: 2.3 million years
Character composition:
• Length: 14
• Lowercase: ✓
• Uppercase: ✓
• Numbers: ✓
• Symbols: ✓
• Unique chars: 13
Feedback:
• Consider avoiding common password patterns
• Excellent use of character variety
📋 CORPORATE Policy Requirements:
- Length: 12-128 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one symbol
- At least 8 unique characters
- No common passwords or words
- No keyboard patterns
use password_policy::{CorporatePolicy, PasswordPolicy, PasswordManager};
fn main() {
// Direct policy usage
let policy = CorporatePolicy::default();
// Generate compliant password
let password = policy.generate();
println!("Generated: {}", password);
// Verify compliance
if policy.meets_requirements(&password) {
println!("✓ Password meets policy requirements");
}
// Analyze strength
let analysis = policy.analyze_strength(&password);
println!("Strength: {} (Score: {})", analysis.strength, analysis.score);
println!("Entropy: {:.1} bits", analysis.entropy);
// Batch operations with manager
let manager = PasswordManager::new();
let passwords = manager.generate_batch(10, Some("corporate"));
let analyses = manager.analyze_batch(&passwords, Some("corporate"));
for (pwd, analysis) in passwords.iter().zip(analyses.iter()) {
println!("{}: {} ({})", pwd, analysis.strength, analysis.score);
}
}
# 1. Run the demo interface
$ cargo run
Password Generator & Strength Analyzer
=====================================
💡 Tip: Use 'password-tool --help' for CLI usage
🏢 Corporate Policy Passwords:
1. M8#kL5@pQ2&wR9!tU
2. N4$vB7@xC3*zA6#eY
3. P9&qM1@jL8#kN5!sW
🔒 High-Security Policy Passwords:
1. X7$kL9@nQ2&mP5!wR8#tU3*vY6+dH4
2. B4#zC9@mK6&qP2!xL5*sW8+nR7$jM1
3. F3&jM8@vN5#kQ9!tL2*pW6+rY4$bC7
📊 Password Strength Analysis:
🔑 Password: password123
Strength: Very Weak (Score: 15)
Entropy: 39.8 bits
Time to crack: 3 hours
Feedback:
• Password is too short
• Add symbols for better security
• Avoid common passwords and words
🔑 Password: MyP@ssw0rd!2024
Strength: Good (Score: 78)
Entropy: 79.2 bits
Time to crack: 89 thousand years
Feedback:
• Consider avoiding common password patterns
• Good use of character variety
🔑 Password: X7$kL9@nQ2&mP5!wR8#tU3*vY6+
Strength: Very Strong (Score: 98)
Entropy: 158.7 bits
Time to crack: Centuries
Feedback:
• Excellent password!
📋 Corporate Policy Requirements:
- Length: 12-128 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one symbol
- At least 8 unique characters
- No common passwords or words
- No keyboard patterns
📋 High-Security Policy Requirements:
- Minimum length: 16 characters
- Must contain uppercase, lowercase, numbers, and symbols
- Minimum entropy: 60.0 bits
# 2. CLI usage examples
$ cargo run -- generate -c 3 -a
🔐 Generating 3 password(s) with corporate policy:
1. H2&mK8@qL5#pN9!wT
Strength: Strong (Score: 89)
2. F7$jM4@vB6*xC3#eZ
Strength: Strong (Score: 85)
3. R9&kL1@nQ8#mP4!sY
Strength: Strong (Score: 87)
$ cargo run -- analyze "weakpassword"
📊 Analyzing password strength with corporate policy:
Password: weakpassword
Strength: Very Weak (Score: 8)
Entropy: 43.9 bits
Time to crack: 4 days
Character composition:
• Length: 12
• Lowercase: ✓
• Uppercase: ✗
• Numbers: ✗
• Symbols: ✗
• Unique chars: 9
Feedback:
• Add uppercase letters
• Add numbers
• Add symbols for better security
$ cargo run -- requirements -p high-security
📋 HIGH-SECURITY Policy Requirements:
- Minimum length: 16 characters
- Must contain uppercase, lowercase, numbers, and symbols
- Minimum entropy: 60.0 bits
This tool provides a complete solution for modern password security needs, combining ease of use with enterprise-grade security features.