NP Security

NP SECURITY

Training & Services

1. System Overview

The NP Security Certificate Management System is a web-based application that allows administrators to:

  • Manage student records (add, edit, view, delete)
  • Generate professional certificates with unique IDs
  • Embed QR codes on each certificate for instant verification
  • Provide public verification via QR code scan
  • Download certificates as high-resolution PNG images

The system serves as both a public-facing website (course listings, about info, contact) and an admin backend (student management, certificate generation).

2. Technology Stack

Component Technology Purpose
BackendPython FlaskWeb server, routing, authentication
DatabaseSQLiteStudent and admin data storage
FrontendHTML/CSS/JSResponsive web interface
CertificatePillow (PIL)Image generation and rendering
QR Codeqrcode libraryUnique QR code per certificate
AuthWerkzeugPassword hashing, session management
FontsGoogle FontsPlayfair Display, Poppins, Inter

3. Complete Workflow

1

Admin Login

Administrator signs in at /login with username and password. Session is secured with Flask's signed cookies.

2

Dashboard Overview

Dashboard shows total students, active students, certificates issued, and grade distribution. Quick actions for adding and viewing students.

3

Add Student Record

Navigate to Students → Add Student. Fill in the student's personal details (name, surname, ID, phone, email), course information (course name, grade level, duration), and optional notes.

4

Student Listed in Database

The student appears in the main Students table with status "Active" and certificate status "Pending". Search, filter by grade or status.

5

Generate Certificate

On the student's edit page, click Generate Certificate. The system:

  • Creates a unique certificate ID (format: NP-XXXXXXXX)
  • Generates a QR code linking to /verify/<CERT_ID>
  • Renders the full certificate image using Pillow
  • Saves the PNG to static/certificates/
  • Updates the student record with certificate ID and path
6

View & Download Certificate

The certificate is displayed in a preview page. Administrator can download the high-resolution PNG for printing or digital distribution.

7

QR Code Verification

Anyone with the certificate can scan the QR code (or visit the verify URL) to confirm its authenticity. The public verification page displays the student's name, course, grade, and certificate ID in a tamper-evident layout.

4. Admin Login

Access the admin panel at /login. Default credentials:

Username: admin

Password: npadmin2026

Important: Change the default password immediately after first login. Update the password hash in production by creating a new admin user or modifying the app.py setup script.

Passwords are hashed using Werkzeug's generate_password_hash() (PBKDF2-SHA256). Sessions are managed via Flask's signed cookie system.

5. Student Management

Adding a Student

  1. Click "+ Add Student" from the Dashboard or Students page
  2. Fill in required fields (First Name, Surname, Course)
  3. Optional fields: ID Number, Phone, Email, Grade, Duration, Notes
  4. Click "Add Student" to save

Editing a Student

Click the edit icon (✎) next to any student in the table. Update field values and click "Save Changes". You can also change the student's status here (Active, Completed, Inactive).

Deleting a Student

Click the delete icon (✕) next to a student. A confirmation dialog will appear. Deletion is permanent and also removes any generated certificate file.

Search & Filter

Use the search bar to find students by name, surname, ID number, or certificate ID. Filter by grade level or status using the dropdown menus.

6. Certificate Generation

How to Generate a Certificate

  1. Navigate to the student's edit page
  2. Click "Generate Certificate" button
  3. The system creates a unique certificate ID in the format NP-XXXXXXXX
  4. Certificate is rendered as a PNG image (1400 × 1000 px, 300 DPI)
  5. You are redirected to the certificate preview page

What the Certificate Contains

  • NP Security logo (from original branding)
  • Company name and registration details (PSIRA, CIPC)
  • Student's full name (uppercase, prominent)
  • Course name and grade level
  • Duration of training
  • Issue date
  • Unique certificate ID in monospace font
  • QR code linking to the verification page
  • Gold decorative border and accents (#d4af37)
  • Dark theme background (#1a1a19) matching brand

Certificate ID Format

Format: NP-XXXXXXXX

Example: NP-A7K2M9X1

Generated using secrets.choice() with uppercase letters and digits (8 characters). Collision check ensures uniqueness.

7. QR Code Verification

How QR Verification Works

  1. Each certificate has a unique QR code printed on it
  2. The QR encodes the full URL: https://<domain>/verify/<CERT_ID>
  3. Scanning the QR opens the verification page in a browser
  4. The verification page queries the database for the certificate ID
  5. If found: displays a green "Verified" badge with student details
  6. If not found: displays a red "Invalid" warning

Verification URL

Public: https://np.marutechcafe.co.za/verify/NP-A7K2M9X1

Security Features

  • Certificate IDs are cryptographically random (secrets module)
  • No two certificates share the same ID (database unique constraint)
  • Verification is read-only — no modification possible via QR scan
  • Invalid/unknown IDs show a clear warning with contact details
  • Certificate images are generated server-side, not editable via URL

8. Certificate Layout

The certificate is a 1400 × 1000 pixel PNG image rendered with the following layout (top to bottom):

+--------------------------------------------------+
|  GOLD DECORATIVE BORDER (3px + 1px inner)        |
|                                                    |
|              [NP SECURITY LOGO]                    |
|              NP SECURITY                           |
|         TRAINING AND SERVICES                      |
|     PSIRA: 3184406/T2242 | CIPC: ...              |
|                                                    |
|        = CERTIFICATE OF COMPLETION =               |
|                                                    |
|           This certifies that                      |
|                                                    |
|          STUDENT NAME SURNAME                      |
|                                                    |
|     has successfully completed the                 |
|                                                    |
|      Grade X - Course Name                         |
|       Duration: X weeks                            |
|       Issued: DD Month YYYY                        |
|       Certificate ID: NP-XXXXXXXX                  |
|                                                    |
|              [QR CODE]                             |
|         Scan to verify certificate                 |
|                                                    |
|   NP Security Training and Services                |
|   PSIRA: ... | CIPC: ... | Tel: 078 460 6540      |
|   This certificate is verified electronically.     |
+--------------------------------------------------+
                

Color scheme: Dark background (#1a1a19), Gold text/accent (#d4af37), White text (#ffffff), Light gray (#cccccc), Teal detail (#4a90a4).

9. Deployment

Local Development

# Install dependencies
pip install -r requirements.txt

# Run the app
python app.py

# Access at http://localhost:5000

Production Deployment

For production, use Gunicorn with a reverse proxy (Nginx):

# Run with gunicorn
gunicorn -w 4 -b 0.0.0.0:8000 app:app

# Recommended: Set SECRET_KEY environment variable
export SECRET_KEY="your-secure-random-key"

Environment Variables

VariableDefaultDescription
SECRET_KEYnp-safety-secret-key...Flask session signing key
PORT5000Server port

Database

The system uses SQLite by default. The database file (instance/npsafety.db) is created automatically on first run. For production with multiple workers, consider migrating to PostgreSQL.

10. FAQ

How do I reset the admin password?

Delete the database file (instance/npsafety.db) and restart the app. The default admin is re-created automatically. Alternatively, use a Python shell to update the hash directly.

Can I customise the certificate design?

Yes. Edit the utils/certificate.py file to change colors, fonts, layout, text, or add new elements. The certificate is generated entirely with Pillow.

What if the QR code is scanned and the certificate is fake?

The verification page will show "Certificate Not Found" with a warning. The invalid cert ID is displayed, and the page advises contacting NP Security at 078 460 6540.

Can I print the certificates?

Yes. Download the PNG from the certificate preview page and print at any standard printer. The certificate is designed at 1400x1000px at 300 DPI, suitable for A4 landscape printing.

How do I add more admin users?

Use the Flask shell or add a route in app.py. The default admin is created automatically if no admin exists.

Is the QR code unique per certificate?

Yes. Each certificate gets a cryptographically random 8-character ID. The database enforces a unique constraint, so no two certificates can have the same ID.