Authentication Routes
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Authentication Routes module provides the primary entry point for teams participating in the Debug Arena. It manages team registration, secure login through password hashing, and session management. This system ensures that only registered squads can access the competition dashboard and submit solutions to debugging challenges.
The module is implemented as a Flask Blueprint, which is registered in the main application entry point to handle all /register, /login, and /logout endpoints. It interacts directly with the Team data model to persist participant information and track progress across sessions.
Sources: routes/auth_routes.py:1-7, app.py:41-45
Authentication Architecture
The authentication system utilizes a client-server model where team credentials are submitted via HTML forms, processed by Flask routes, and validated against an SQLite or PostgreSQL database.
Core Components
- Blueprint (
auth): Encapsulates all authentication-related routing logic to maintain a modular codebase. - Security Utilities: Uses
werkzeug.securityfor implementing PBKDF2 with SHA-256 hashing for password storage and verification. - Session Management: Utilizes Flask's
sessionobject to storeteam_idandteam_nameupon successful authentication, enabling stateful interactions across the arena.
Sources: routes/auth_routes.py:4-7, app.py:19-24, routes/auth_routes.py:44-46
Data Flow for Registration
When a team registers, the system validates the uniqueness of the team name before hashing the password and committing the new record to the database.
This diagram illustrates the registration logic flow where uniqueness is enforced at the application level.
Sources: routes/auth_routes.py:9-32
Endpoint Specifications
The following table details the endpoints managed by the auth blueprint:
| Endpoint | Method | Description | Target Template |
|---|---|---|---|
/register | GET | Renders the team registration form. | register.html |
/register | POST | Processes team registration and hashes passwords. | N/A (Redirects) |
/login | GET | Renders the team login form. | login.html |
/login | POST | Validates credentials and initializes session. | N/A (Redirects) |
/logout | GET | Clears the current session and redirects to index. | N/A (Redirects) |
Sources: routes/auth_routes.py:9-52
Team Data Model
The Team class serves as the foundation for authentication, containing fields for credentials and tracking.
| Field | Type | Constraint | Description |
|---|---|---|---|
id | Integer | Primary Key | Unique identifier for the team. |
team_name | String(50) | Unique, Not Null | The public name of the squad. |
password | String(255) | Not Null | Hashed password string. |
email | String(120) | Unique, Not Null | Contact email for the team. |
college | String(100) | Not Null | Academic affiliation of the team. |
Sources: models/team.py:5-15
Security Implementation
Security is handled through a combination of server-side hashing and client-side UI feedback.
Password Hashing
The system never stores plain-text passwords. During registration, the generate_password_hash function is called with the pbkdf2:sha256 method. During login, check_password_hash verifies the user-provided input against the stored hash.
Sources: routes/auth_routes.py:25-28, routes/auth_routes.py:43-46
Session Logic
Successful login populates the Flask session, which is subsequently used by the base.html template to toggle navigation visibility.
This sequence diagram shows the interaction between the user interface, the authentication route, and the database session storage.
Sources: routes/auth_routes.py:35-49, templates/base.html:56-68
Frontend Integration
The authentication routes serve specific templates styled with Tailwind CSS to provide a consistent dark-themed user experience.
register.html: Contains inputs forteam_name,college,email, andpassword.login.html: Focuses onteam_nameandpasswordfor existing teams.base.html: Includes a global navigation bar that dynamically displays the team name ifsession['team_name']is present, or provides links to Login/Register if not.
Sources: templates/register.html:10-26, templates/login.html:10-20, templates/base.html:56-68
Conclusion
The Authentication Routes module establishes a secure and user-friendly gateway to the Debug Arena. By combining robust hashing algorithms, session-based state management, and clear UI feedback via flashed messages, it provides the necessary infrastructure for competitive team-based debugging sessions.
Sources: routes/auth_routes.py:1-52, models/team.py:1-25