Introduction
Weak passwords remain one of the biggest causes of account break-ins. This tool explains why a password is weak and generates strong ones with Python's secrets module, which is designed for security.
Problem statement
Objectives
- Combine several rules into a score
- Use str.translate for leetspeak normalisation
- Use regular expressions to detect repeats
- Understand why secrets, not random, is used for passwords
Features
- 0–100 score with a verdict
- Explanations for every weakness
- Common-password and leetspeak detection
- Sequence and repeat detection
- Secure generator guaranteeing all character classes
Concepts demonstrated
- Scoring heuristics
- String methods and translation tables
- Cryptographically secure randomness
- Input masking
System architecture
score computes points from length and character classes, then applies penalties using has_sequence, a regex for repeated characters and a common-password set checked against a leetspeak-normalised copy. verdict maps points to a label. generate picks one character from each pool, fills the rest and shuffles, using secrets unless a seeded random.Random is given for demos.
Folder structure
Complete source code
main.py
What each file does
- main.py
- The whole program: data classes, validation, the command loop and the report.
How to run it
Run
Test against the expected output
Expected output
Generated by running the project with tests/sample-input.txt. Your output should match tests/expected-output.txt exactly.
check 123456 check P@ssw0rd check sunshine2026 check abcd1234XY check aaaPython!9 check Tr!cky-Monsoon-42 check correct horse battery staple generate 16 seed 7 generate 4 seed 1 generate twelve help quit
Testing
- Run
python main.py < tests/sample-input.txtand compare withtests/expected-output.txt. - 123456 scores 0 and P@ssw0rd is recognised as the common password 'password'.
- abcd1234XY loses points for alphabet and number sequences.
- Tr!cky-Monsoon-42 scores 91 (very strong); a length of 4 and 'twelve' are rejected by generate.
Common errors
Generated passwords are predictable
Use secrets.choice and secrets.SystemRandom, never the random module, for real passwords.
P@ssw0rd passes as strong
Normalise leetspeak with str.translate before comparing with the common list.
Possible improvements
- Check passwords against a larger breach list
- Estimate crack time from the number of possible combinations
- Generate memorable passphrases from a word list
Additional challenges
- 1Detect dates such as 2026 or 27112026 inside passwords.
- 2Add an option to exclude look-alike characters (0/O, 1/l).
- 3Score with entropy in bits instead of points.
Built and tested it yourself? Mark it to update your dashboard.