1 / 28
Capstone Project · Grade 8 · Chapter 10

Mini Project Part 2: Integration & Showcase

Integrating CSV file persistence, adding AI improvement recommendations, refactoring for PEP 8, and live smartboard presentations!

Launch Day

From Code Snippets to Complete Software

Today we take our individual modules (strength checker, hashing engine, menu loop) and wire them up with CSV file persistence and AI advice generators into a complete, enterprise-ready CLI application!

Target: Zero crashes on invalid input, automated file saving, and clean smartboard demo.
Lesson Objectives

What We Will Complete Today

System Architecture

Full Application Pipeline

1. BOOT
Load vault.csv into in-memory dictionary.
2. CLI MENU
Capture user actions (Audit, Register, AI Hint).
3. LOGIC ENGINE
Compute SHA-256 hash & entropy score.
4. PERSIST
Save updated user records back to CSV file.
CSV Persistence Module

Implementing `save_vault_to_csv()`

import csv def save_vault_to_csv(vault, filename="vault.csv"): try: with open(filename, "w", newline="") as f: fieldnames = ["username", "hash", "salt", "score"] writer = csv.DictWriter(f, fieldnames=fieldnames) writer.writeheader() for uname, data in vault.items(): writer.writerow({ "username": uname, "hash": data["hash"], "salt": data["salt"], "score": data["score"] }) print(f"[+] Saved {len(vault)} records to {filename}") except IOError as e: print(f"[-] File Write Error: {e}")
CSV Load Module

Implementing `load_vault_from_csv()`

def load_vault_from_csv(filename="vault.csv"): vault = {} try: with open(filename, "r") as f: reader = csv.DictReader(f) for row in reader: vault[row["username"]] = { "hash": row["hash"], "salt": row["salt"], "score": int(row["score"]) } except FileNotFoundError: print("[!] Vault file not found. Starting with empty vault.") return vault
Adding AI Feature

AI-Powered Security Recommendation Engine

Generate dynamic improvement advice based on missing password entropy rules:

def generate_ai_feedback(password): advice = [] if len(password) < 12: advice.append("• Increase length to 12+ characters (or use a 4-word passphrase).") if not any(c.isdigit() for c in password): advice.append("• Insert at least one numeric digit.") if not any(not c.isalnum() for c in password): advice.append("• Include special symbols like @, #, or $-") if not advice: return "🌟 Excellent! Your passphrase passes all security checks." return "\n".join(advice)
Defensive Code Quality

Fragile App vs. Enterprise CyberShield CLI

Fragile Prototype

Crashes if file is missing. Stores plaintext passwords. No docstrings or input checks.

Enterprise CyberShield CLI

Uses try/except, salted SHA-256 hashes, CSV persistence, and PEP 8 docstrings.

Scenario Analysis

Edge Case Bug Hunting

QA TESTING

Test your application against these 4 edge case scenarios:

  1. Launching app when vault.csv does NOT exist.
  2. Registering a user that already exists in the vault dictionary.
  3. Typing letters when prompted for numeric menu options.
  4. Entering a password with trailing spaces.
Spot the Mistake

3 Integration Bugs Found in Testing

# Bug 1: TypeError when loading score from CSV score = row["score"] + 5 # Need int(row["score"])! # Bug 2: Missing newline in DictWriter initialization with open("vault.csv", "w") as f: # Missing newline=""! Adds extra blank rows. # Bug 3: Duplicate username overwrite vault[uname] = new_data # Overwrites existing without warning!
Documentation Workshop

Writing Clean Function Docstrings

Format function docstrings following PEP 257 standard conventions:

def hash_password(password: str, salt: str = None) -> tuple: """Computes SHA-256 cryptographic hash of a salted password. Args: password (str): Raw user password input. salt (str, optional): Hexadecimal salt string. Defaults to None. Returns: tuple: (hex_hash, salt_string) """
Hands-on Challenge

Final Integration Assembly

Combine all modules into a single executable script cybershield_app.py and verify full persistence loop!

Check Your Understanding

Why is `newline=""` passed when opening CSV files in Python `csv.writer`?

ATo encrypt the CSV text content
BTo prevent Windows from inserting blank lines between CSV rows
CTo delete the header row automatically
DTo force all numbers to become floating point
Click to reveal answer
Check Your Understanding

What happens if `load_vault_from_csv()` encounters a missing file?

AThe computer shuts down immediately
B`try/except FileNotFoundError` catches it and initializes an empty vault dict
CPython crashes with an unhandled exception stack trace
DIt downloads a vault file from the internet
Click to reveal answer
Check Your Understanding

What is the primary goal of defensive input validation?

ATo make the application run twice as fast
BTo handle unexpected user inputs without crashing or corrupting data
CTo automatically generate passwords for users
DTo reduce code length by half
Click to reveal answer
Check Your Understanding

Which tool converts CSV string representations of numbers back into integers?

Astr()
Bint()
Clen()
Dhash()
Click to reveal answer
Smartboard Showcase

Student Project Demonstrations

Each student team presents their running CyberShield CLI tool on the smartboard:

1. LAUNCH
Run python cybershield_app.py in terminal.
2. AUDIT
Test weak vs. strong passphrases live.
3. REGISTER
Create user account and generate salt/hash.
4. PERSIST
Open vault.csv to prove record saved!
Evaluation Rubric

Project Evaluation Criteria

1. Functionality (40%)

All core security modules execute correctly; CSV save/load works seamlessly.

2. Robustness & Safety (30%)

Handles invalid menu choices and missing files without crashing (`try/except`).

3. Code Quality (20%)

PEP 8 compliance, clean variable names, modular functions, and docstrings.

4. Presentation & Demo (10%)

Clear smartboard demonstration explaining architectural decisions.

Self-Assessment

Project Reflection & Code Polish

Audit your own project file against the checklist before final submission:

Grade 8 CS Retrospective

Your Journey Across Grade 8 Computer Science

1. Cybersecurity

Password entropy, SHA-256 hashing, salts, 2FA, and attack vectors.

2. AI Systems

4-layer architecture, training vs inference, edge computing, prompt engineering.

3. Advanced Python

Scope, functions, lists, dictionaries, file I/O, and defensive `try/except` code.

Key Skills Mastered

What You Can Now Build

Exit Ticket

Final Course Reflection

What was the most challenging bug you solved during the CyberShield mini-project, and how did you debug it?
Course Milestone Reached

🎉 Congratulations!

You have successfully completed Grade 8 Computer Science & AI Systems Literacy!

You are now equipped with the engineering foundations to build software and understand modern AI architectures.
Digital Badge

Certified Grade 8 CS Engineer

Python & Security Master

Demonstrated competence in functions, scope, data structures, persistent file I/O, and cryptographic security engines.

AI Systems Literacy

Demonstrated mastery of AI systems architecture, pipeline design, and advanced prompt engineering.

Looking Ahead

What Comes Next in Grade 9 & Beyond?

In high school computer science, you will explore object-oriented programming (OOP), web application APIs, neural network creation with PyTorch, and cloud deployments!

Final Words

Keep Building & Coding!

Technology is not magic; it is built by curious minds like yours line of code by line of code. Never stop asking how systems work!