Comprehensive User Management and Progress Analytics
This guide details the authentication system and score tracking infrastructure implemented in CyberSmart. The platform features secure user management, persistent session handling, and comprehensive analytics for tracking cybersecurity learning progress.
- Secure Authentication: PBKDF2 password hashing with salt protection
- Session Management: Persistent login sessions across assessments
- Score Analytics: Individual and community progress tracking
- Assessment Types: Pre-assessment, Post-assessment, and Practice modes
- Progress Visualization: Beautiful UI with gradient cards and metrics
- SQLite Database: Local data storage with relational structure
- Authentication Layer: Secure login/register with session persistence
- Score Engine: Multi-dimensional assessment scoring system
- Analytics Dashboard: Real-time progress visualization
Welcome Screen → Login/Register → Exam Selection → Assessment → Results & History
- Secure Registration: Username/password with confirmation validation
- Login Persistence: Sessions maintained across browser refreshes
- Password Security: PBKDF2 hashing with 100,000 iterations and random salt
- Session Management: Unique session IDs for each assessment attempt
- Welcome Screen: Beautiful gradient UI with login/register options
- Login Form: Existing user authentication
- Registration Form: New user account creation with password confirmation
- Dashboard: User-specific score history and logout functionality
.auth-title {
color: #1a1a1a;
font-size: 3rem;
font-weight: 800;
}
.exam-type-container {
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
border-radius: 12px;
color: white;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_login TIMESTAMP
);CREATE TABLE user_scores (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
session_id TEXT NOT NULL,
exam_type TEXT NOT NULL, -- 'pre', 'post', 'practice'
phishing_score REAL,
password_match_score REAL,
password_strength_entropy REAL,
overall_score REAL,
completed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users (id)
);CREATE TABLE user_sessions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
session_id TEXT UNIQUE NOT NULL,
exam_type TEXT NOT NULL,
started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
completed_at TIMESTAMP,
is_active BOOLEAN DEFAULT 1,
FOREIGN KEY (user_id) REFERENCES users (id)
);- One-to-Many: Users → User Scores (one user, multiple assessments)
- One-to-Many: Users → User Sessions (one user, multiple sessions)
- Foreign Keys: Maintain referential integrity across tables
- Purpose: Baseline cybersecurity knowledge measurement
- Scoring: Initial competency across all security domains
- Analytics: Establishes learning starting point
- Purpose: Learning effectiveness measurement
- Scoring: Final competency after platform interaction
- Analytics: Improvement calculation vs pre-assessment
- Purpose: Continuous learning without formal evaluation
- Scoring: Tracked but not included in improvement metrics
- Analytics: Progress monitoring and skill reinforcement
# Sigmoid transformation for balanced scoring
def get_phishing_score(correct_answers: int, total_questions: int) -> float:
base_score = (correct_answers / total_questions) * 200
sigmoid = lambda x: 200 / (1 + np.exp(-0.05 * (x - 100)))
return round(sigmoid(base_score), 2)# Exponential weighting for accuracy emphasis
def get_match_score(correct_matches: int, total_matches: int) -> float:
base_score = (correct_matches / total_matches) * 200
weighted_score = 200 * (1 - np.exp(-0.02 * base_score))
return round(weighted_score, 2)- Calculation: Mathematical entropy using character set diversity
- Scale: Normalized to 0-200 range for consistency
- Factors: Length, complexity, pattern analysis
- Individual Progress: Pre vs post assessment comparison
- Score History: Complete assessment timeline
- Improvement Tracking: Quantified learning gains
- Performance Breakdown: Domain-specific strengths/weaknesses
- Community Averages: Aggregate performance statistics
- Improvement Trends: Platform effectiveness measurement
- Participant Counts: Unique user engagement metrics
- Comparative Analysis: Individual vs community performance
.score-history-container {
background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
border-radius: 12px;
padding: 1.5rem;
color: white;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.score-card {
background: rgba(255,255,255,0.1);
border-radius: 8px;
padding: 1rem;
backdrop-filter: blur(10px);
border: 1px solid rgba(255,255,255,0.2);
}- Gradient Cards: Beautiful score display with visual hierarchy
- Sidebar Integration: Persistent score history with logout option
- Conditional Display: Assessment history only shown when relevant
- Progress Indicators: Visual representation of improvement metrics
- Authentication → Secure login with beautiful gradient UI
- Exam Selection → Choose assessment type with clear descriptions
- Assessment Flow → Maintained existing 4-step game progression
- Results Display → Comprehensive scoring with historical context
- Dashboard Access → Sidebar navigation with logout functionality
- Hashing Algorithm: PBKDF2 with SHA-256
- Salt Generation: 32-byte random salt per password
- Iteration Count: 100,000 iterations for computational resistance
- Storage Format: Salt + hash concatenation for verification
- Unique Session IDs: MD5 hash of user ID, timestamp, and exam type
- Session Persistence: Maintains login state across page refreshes
- Automatic Cleanup: Sessions marked inactive upon completion
- Secure Storage: Server-side session management
- SQL Injection Prevention: Parameterized queries throughout
- Input Validation: Sanitization of all user inputs
- Error Handling: Graceful failure with informative messages
- Data Isolation: User-specific data access controls
def verify_password(self, password: str, stored_hash: str) -> bool:
"""Secure password verification with salt extraction"""
if len(stored_hash) < 64:
return False
salt = bytes.fromhex(stored_hash[:64])
stored_password_hash = stored_hash[64:]
password_hash = hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt, 100000)
return password_hash.hex() == stored_password_hashdef register_user(self, username: str, password: str) -> Tuple[bool, str]:
"""Secure user registration with duplicate checking"""
# 1. Check username availability
# 2. Hash password with salt
# 3. Insert user record
# 4. Return success statusdef save_user_scores(self, user_id: int, session_id: str, exam_type: str,
scores...):
"""Save assessment scores and mark session complete"""
# 1. Insert score record
# 2. Update session completion
# 3. Maintain data integritydef get_global_averages(self) -> Dict:
"""Calculate community statistics with unique user counting"""
# 1. Aggregate pre-assessment averages
# 2. Aggregate post-assessment averages
# 3. Calculate improvement metrics
# 4. Count unique participants- Educational Effectiveness: Pre/post assessment comparison shows learning impact
- User Engagement: Beautiful UI encourages continued platform usage
- Data Privacy: Local SQLite storage keeps user data secure
- Scalable Analytics: System supports unlimited users and assessments
- Security Best Practices: Industry-standard authentication and data protection