What it shows
The program scores a password on length, capital letters, small letters, digits and symbols. It shows how longer and mixed passwords are harder to guess and how string methods work.
The science
The number of guesses an attacker needs grows quickly with length and with the number of kinds of characters used. A password of 8 lowercase letters has about 200 billion possibilities, while 12 characters mixing letters, digits and symbols has many trillions of times more. The string methods isupper, islower, isdigit and isalnum test one character at a time.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A computer, laptop or phone with a browser (free)
- Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
- A list of 10 made-up practice passwords (never type your real password)
- A notebook and a pencil
Safety
For this project: Test only with made-up passwords. Never type a real password into any program you are testing.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Create strength.py and define def check(p): with score = 0 as the first line inside it.
Add if len(p) >= 8: score += 1 and if len(p) >= 12: score += 1.
Add if any(c.isupper() for c in p): score += 1, then the same with islower() and isdigit().
Add if any(not c.isalnum() for c in p): score += 1 for symbols, then end with return score.
Make a list common = ["password", "123456", "qwerty", "india123"] and at the start of check add if p.lower() in common: return 0.
In the main part ask text = input("Practice password: ") and print the score out of 6.
Convert the score into words with if score <= 2: print("Weak"), elif score <= 4: print("Medium") and else: print("Strong").
Test your 10 made-up passwords and write a table of the score against length and character types.
What you should see
Short or common passwords score weak, and long ones with capital letters, digits and symbols score strong. The table shows that length and variety both raise the score.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1Why is a longer password better?
There are many more combinations to try, so guessing takes far longer.
2What does any() do?
It returns True if at least one item in the group is True.
3Why reject common passwords?
Attackers try common ones first.
4Should you test real passwords?
No, never type a real password into a test program.
Take it further
Calculate the number of possible passwords as the pool size raised to the length and print it with the score.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Computer & office
Safe UPI and Digital Payments
Pay and receive money online, and recognise the tricks fraudsters use
Find out more about computing and coding
Free, well-known places to explore the subject further. Ask a grown-up before you sign up for anything or type your name anywhere.
