Add user authentication system
- Implement secure user registration and login - Add password hashing with PBKDF2 and random salts - Create session-based authentication with secure tokens - Support user deactivation and session management - Include comprehensive unit tests for authentication - Integrate authentication demo into main application 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
22
main.py
22
main.py
@@ -6,6 +6,7 @@ Main application entry point for the sandbox project.
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from src.auth import UserManager
|
||||
|
||||
def load_config():
|
||||
"""Load configuration from config.json"""
|
||||
@@ -24,6 +25,27 @@ def main():
|
||||
|
||||
if config.get("debug"):
|
||||
print("Running in debug mode")
|
||||
|
||||
# Initialize authentication system
|
||||
auth_manager = UserManager()
|
||||
print("\n--- Authentication System Demo ---")
|
||||
|
||||
try:
|
||||
# Register a demo user
|
||||
auth_manager.register_user("demo_user", "demo@example.com", "secure_password123")
|
||||
print("✓ Demo user registered successfully")
|
||||
|
||||
# Authenticate the user
|
||||
session_token = auth_manager.authenticate("demo_user", "secure_password123")
|
||||
print("✓ User authenticated successfully")
|
||||
print(f"Session token: {session_token[:20]}...")
|
||||
|
||||
# Validate session
|
||||
username = auth_manager.validate_session(session_token)
|
||||
print(f"✓ Session validated for user: {username}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"✗ Authentication error: {e}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user