Python Password Generator and Strength-Check Examples
Two small Python command-line tools: a random password generator with guaranteed numbers of digits, uppercase, lowercase, and special characters, and a password strength checker that rates a password by the number of possible character combinations.
Python projects · CLI learning examples
Start here
Read the requirements and any configuration below, then follow the usage example. Source paths below are relative to the repository root; run commands from the working directory stated in Usage. This example’s source is in Password Utility/Cosole_Code/. Install any third-party packages in an isolated Python environment.
Overview
This project contains two independent scripts:
- Password Generator — creates a random password of configurable length and character composition
- Password Strength Validator — assesses how strong a given password is based on its character variety
Prerequisites and installation
No external dependencies. Both scripts use only Python standard library modules (random, string, re, os).
Scripts
Password Generator (Password_Generator.py)
Generates a random password based on specified requirements.
Default settings (hardcoded in __main__):
| Parameter | Value |
|---|---|
| Total length | 30 characters |
| Digits | 5 |
| Uppercase letters | 5 |
| Lowercase letters | 5 |
| Special characters | 5 |
| Remaining | Random mix of all character types |
The generated characters are shuffled so the guaranteed characters are not grouped at the start.
Security note: the generator uses Python’s
randommodule, which is designed for simulations, not security. For real passwords, use thesecretsmodule (for examplesecrets.choice(...)andsecrets.SystemRandom().shuffle(...)) or a password manager.
Usage (from the Cosole_Code folder):
python Password_Generator.py
The script prints one 30-character password; repeated output is possible with any finite random generator.
Password Strength Validator (PasswordStregth.py)
Evaluates a password by calculating the total number of possible combinations given its character composition: 26 options for each lowercase letter, 26 for each uppercase letter, 10 for each digit, and the length of the regex pattern string for each matched special character, multiplied together. That last factor counts regex syntax too, so it is not the size of the actual special-character alphabet.
Strength levels:
| Strength | Threshold (combinations) |
|---|---|
| Very Strong | ≥ 10¹⁶ |
| Strong | ≥ 10¹² |
| Moderate | ≥ 10⁸ |
| Weak | ≥ 10⁴ |
| Very Weak | < 10⁴ |
Usage:
python PasswordStregth.py
The script runs in a loop, letting you check multiple passwords until you choose to exit.
Example session (results confirmed by running the script):
Enter your password: hello
Weak
More ! (Y|N) : Y
Enter your password: P@ssw0rd!2024
Very Strong
More ! (Y|N) : N
The rating only considers length and character types.
P@ssw0rd!2024scores Very Strong even though it follows a very common pattern that password crackers try early. For a realistic estimate, use a library such aszxcvbn, which also checks dictionary words and common substitutions.
Architecture
Password Utility/
└── Cosole_Code/
├── Password_Generator.py # Random password generator
└── PasswordStregth.py # Password strength validator
Related documentation
- Use Windows Login — verify Windows credentials
- Steganography — hide text in images
- Back to all Python projects
Documentation links
Read all Python Projects and Code Examples guides online · Project overview · All developer projects