Skip to content

Intermediate · Projects: put it all together · topic 35 of 50 · 30 min

Project: password strength checker

Explanation

You will build a password strength checker like the one you see on sign-up forms. It checks length, capital letters, small letters, digits and symbols, gives a score and a label (weak, medium or strong) and lists what is missing. You will also learn why real sites never store passwords as plain text.

The plan

PartFor our checker
InputOne password (a string)
OutputsA score, a label (weak / medium / strong) and a list of reasons to improve
Stepstest each rule, add up the score, pick a label, collect messages for failed rules

The rules

RuleHow to test it in Python
At least 8 characterslen(pw) >= 8
A small letterany(c.islower() for c in pw)
A capital letterany(c.isupper() for c in pw)
A digitany(c.isdigit() for c in pw)
A symbol like @ # ! ?any(not c.isalnum() and not c.isspace() for c in pw)
Bonus: 12 or more characterslen(pw) >= 12
Think of it like this: Think of the lock on your house. A lock that opens with any thin wire is weak. More pins inside, a stronger body and a longer key make it harder to pick. Each password rule is one more pin; length is the biggest one.

Step 1: test each rule

python
def rules_met(pw):
    return {
        "length": len(pw) >= 8,
        "lower": any(c.islower() for c in pw),
        "upper": any(c.isupper() for c in pw),
        "digit": any(c.isdigit() for c in pw),
        "symbol": any(not c.isalnum() and not c.isspace() for c in pw),
    }

print(rules_met("mango123"))
print(rules_met("Mango@2026"))
A dictionary of True/False values: easy to count and easy to turn into messages.

Step 2: score, label and reasons

python
COMMON = {"password", "123456", "12345678", "qwerty", "india@123", "password@123"}
MESSAGES = {
    "length": "Use at least 8 characters",
    "lower": "Add a small letter",
    "upper": "Add a capital letter",
    "digit": "Add a digit",
    "symbol": "Add a symbol like @ or #",
}

def rules_met(pw):
    return {
        "length": len(pw) >= 8,
        "lower": any(c.islower() for c in pw),
        "upper": any(c.isupper() for c in pw),
        "digit": any(c.isdigit() for c in pw),
        "symbol": any(not c.isalnum() and not c.isspace() for c in pw),
    }

def check_password(pw):
    rules = rules_met(pw)
    score = sum(rules.values()) + (1 if len(pw) >= 12 else 0)
    reasons = [MESSAGES[name] for name, ok in rules.items() if not ok]
    if pw.lower() in COMMON:
        return {"score": 0, "label": "weak", "reasons": ["This is a very common password"]}
    if score <= 2:
        label = "weak"
    elif score <= 4:
        label = "medium"
    else:
        label = "strong"
    return {"score": score, "label": label, "reasons": reasons}

for pw in ["abc", "mango123", "Mango@2026", "Monsoon-Chai-2026", "India@123"]:
    print(pw, check_password(pw))
sum() of True/False values counts the Trues, because True counts as 1.

The score goes from 0 to 6: one point for each of the five rules, and one bonus point for 12 or more characters. 0 to 2 is weak, 3 or 4 is medium, 5 or 6 is strong. Common passwords are always weak, because attackers try them first.

Tip: Length beats tricks. "Monsoon-Chai-2026" is easier to remember and much harder to guess than "M@ng0". A passphrase of three or four random words is a good habit.

Never store plain passwords

A website must check your password at login, but it must never keep the password itself. If the database is ever stolen, plain passwords would be exposed. Instead the site stores a hash. A hash is a fixed-length fingerprint made from the text. The same text always gives the same hash, but you cannot turn the hash back into the text.

python
import hashlib

fingerprint = hashlib.sha256("Mango@2026".encode()).hexdigest()
print(fingerprint)
print(len(fingerprint))  # always 64 hex characters
print(hashlib.sha256("mango@2026".encode()).hexdigest() == fingerprint)  # False: one letter changed
.encode() turns the text into bytes, which hashlib needs.
Careful: SHA-256 is too FAST for passwords: an attacker can try billions of guesses per second. Real sites use slow password hashes such as bcrypt or Argon2, with a random salt (extra random text) for each user. Do not build your own login system for real users; use a well-tested library or framework.

Step 3: test it

  • An empty string should be weak with all five reasons.
  • "Mango@2026" meets all five rules but is under 12 characters: score 5, strong.
  • A common password like "Password" (any case) should be weak.
  • A long phrase with spaces: spaces are not counted as symbols.

Watch the lesson

Project: password strength checker · 1/6

Project: password checker

In this project you will build a password strength checker, like the meter on a sign-up form.

Prefer a video by a teacher? Find free videos on “python password strength checker project” on YouTube ↗

In real life: A sign-up form for a college fest

Students building the registration site for their college fest add a password meter under the password box. As the user types, it shows weak, medium or strong in red, orange or green, and a short list like "Add a digit". The rules are exactly our check_password function; the website just shows its result.

python
pw = "Rangoli2026"
missing = []
if not any(c.isdigit() for c in pw):
    missing.append("Add a digit")
if not any(not c.isalnum() and not c.isspace() for c in pw):
    missing.append("Add a symbol like @ or #")
print(missing)
Rangoli2026 only needs a symbol.

Practice (0/3 done)

Task 1 · Code · Python

Write count_rules(pw) that returns how many of these 5 rules the password meets: at least 8 characters; has a small letter; has a capital letter; has a digit; has a symbol (a character that is not a letter, not a digit and not a space).

Task 2 · Code · Python

Write strength_label(score) for a score from 0 to 6: return "weak" for 0 to 2, "medium" for 3 or 4, and "strong" for 5 or 6.

Task 3 · Code · Python

Write reasons(pw) that returns a list of messages for the rules the password FAILS, in this order: "Use at least 8 characters", "Add a small letter", "Add a capital letter", "Add a digit", "Add a symbol". A password that passes everything gives [].

Quick quiz

Question 1

1.What does any(c.isdigit() for c in "Chai@") return?

Question 2

2.Why does sum(rules.values()) work as a count?

Question 3

3.What should a website store instead of your plain password?

Question 4

4.Why is plain SHA-256 not good enough for storing passwords?

Question 5

5.Which password is strongest by our rules and by common sense?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

← Previous: Project: quiz game with negative marking