Password generator and strength checker
Generate strong passwords and score how strong an existing password is, with clear tips to improve it.
What you'll learn
- โWhy secrets is safer than random for passwords
- โString handling and character classes
- โWriting simple scoring rules and tests
What you'll build
- โGenerate a password of chosen length with chosen character types
- โGenerate memorable passphrases from a word list
- โStrength score 0โ4 with reasons
- โCopies the password to the clipboard
Step-by-step guide
- 1
Generate with secrets
Build the alphabet from string.ascii_lowercase, ascii_uppercase, digits and punctuation, then use secrets.choice in a loop.
- 2
Guarantee every chosen type
Pick at least one character from each selected type first, fill the rest, then shuffle with secrets.SystemRandom().shuffle.
- 3
Add passphrases
Load a word list (for example the EFF short word list), pick 4โ6 words with secrets.choice and join them with "-".
- 4
Score strength
Give points for length (12+, 16+), for each character type and subtract for common patterns like "1234", "password" or repeated characters.
- 5
Explain the score
Return a list of reasons ("Add a symbol", "Avoid common words") alongside the score and print them.
- 6
Write tests
Use pytest to check the generator always includes each selected type and that "password123" scores low.
- 7
Copy to clipboard
pip install pyperclip and call pyperclip.copy(pw) after generating.
๐ Make it stand out
- +Check a password against breach data with the Have I Been Pwned range API (k-anonymity, only 5 hash characters are sent)
- +Add a Tkinter GUI
- +Estimate crack time from the entropy