Project 3: Password Fortress 🔐¶

Difficulty: 🟢 Beginner

Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/password_fortress/.

← Back to index

Description¶

Build a cryptographically secure password generator — a practical first project that produces instantly useful output.

Libraries & Modules¶

  • secrets — cryptographically strong randomness
  • string — character sets (ascii_letters, digits, punctuation)

Python Concepts You'll Practice¶

Functions, f-strings, list comprehensions, join()

🎛️ Parameter Variations¶

  • LENGTH — 8 (weak demo) vs 24 (strong)
  • Toggle USE_UPPER, USE_DIGITS, USE_SYMBOLS
  • COUNT — generate 1 vs 10 passwords at once
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline

from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame

OUTPUT_DIR = Path("outputs") / "password_fortress"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\password_fortress

Step 1 — Build the generator function¶

In [3]:
import secrets
import string

# 🎛️ TWEAK THESE
LENGTH = 16
USE_UPPER = True
USE_DIGITS = True
USE_SYMBOLS = True
COUNT = 5

def generate_password(length=16, upper=True, digits=True, symbols=True):
    alphabet = string.ascii_lowercase
    if upper:
        alphabet += string.ascii_uppercase
    if digits:
        alphabet += string.digits
    if symbols:
        alphabet += "!@#$%^&*-_=+?"
    if not alphabet:
        raise ValueError("At least one character set must be enabled")
    return "".join(secrets.choice(alphabet) for _ in range(length))

passwords = [generate_password(LENGTH, USE_UPPER, USE_DIGITS, USE_SYMBOLS) for _ in range(COUNT)]
for i, p in enumerate(passwords, 1):
    print(f"{i}. {p}")
1. EOCb@?cbr+V36f1U
2. ut9Qb#SKNh&8#RVB
3. g!9e0#!agGl%V?JB
4. sUa5^B8nKffSwbYL
5. ZqSsrIXvD6LfFGC1

Step 2 — Export to a file¶

In [4]:
out = OUTPUT_DIR / "passwords.txt"
out.write_text("\n".join(passwords), encoding="utf-8")
print(f"Saved {len(passwords)} passwords to {out}")
Saved 5 passwords to outputs\password_fortress\passwords.txt

✅ Project complete¶

Check your output folder: outputs/password_fortress/

Next: Project 4: QR Code Crafter · Index