← All video projects

Free video project · Beginner

How long would it take to crack your password? 🔐

A crack-time checker that sizes up a password's character pool, turns guesses into human time, and then generates passwords that would take over a million years.

The video is out Friday 16 October at 6pm.

The code from the video

# How long would it take to crack your password?
import secrets

LOWER = "abcdefghijklmnopqrstuvwxyz"
UPPER = LOWER.upper()
DIGITS = "0123456789"
SYMBOLS = "!@#$%&*?-_"
COMMON = ["password", "123456", "qwerty", "letmein", "iloveyou"]

def pool_size(password):
    size = 0
    if any(c in LOWER for c in password): size += 26
    if any(c in UPPER for c in password): size += 26
    if any(c in DIGITS for c in password): size += 10
    if any(not c.isalnum() for c in password): size += 33
    return size

def how_long(seconds):
    for unit, length in [("years", 31536000), ("days", 86400), ("hours", 3600), ("minutes", 60)]:
        if seconds >= length:
            amount = seconds / length
            if amount > 1000000:
                return "over a million " + unit
            return f"{amount:,.0f} {unit}"
    if seconds < 1:
        return "under a second"
    return f"{seconds:.0f} seconds"

def crack_time(password):
    if password.lower() in COMMON:
        return "instantly"
    guesses = pool_size(password) ** len(password)
    return how_long(guesses / 10_000_000_000)

def make_password(length=16):
    chars = LOWER + UPPER + DIGITS + SYMBOLS
    password = ""
    for _ in range(length):
        password += secrets.choice(chars)
    return password

for pw in ["password", "fluffy", "Fluffy99", "Summer2026!", "correct horse battery", make_password()]:
    print(f"{pw:<24}{crack_time(pw)}")

Run it in your browser with nothing to install, right here on this page.

Make it your own

  1. Add a penalty for passwords that contain a common word anywhere inside them, not just an exact match.
  2. Print a strength label (weak, okay, strong) as well as the time.
  3. Make a passphrase generator that joins four random words with hyphens.

Skills: functions, any(), f-strings, secrets

Start the free lessons More video projects