Secure User Authentication with Session Tokens
AS A network security administrator managing a production monitoring system
I WANT a secure login system with hashed passwords and session tokens stored in a database
SO THAT I can ensure only authorized personnel access the network dashboard, maintain an audit trail of user activity and prevent API credential exposure in client-side code
Acceptance criteria
Given the dashboard is loaded in a browser
When the user is not authenticated
Then they should see a login form (username + password)
Given a user submits valid credentials to /login
When the server validates the bcrypt-hashed password
Then it generates a UUID session token, stores it in SQLite with metadata (user, IP, login timestamp), and returns it to the client
Given a user has a valid session token
When they request /metrics or other protected endpoints
Then the API validates the session token against SQLite and returns data
Given a session token expires (1 hour of inactivity)
When the user tries to access protected endpoints
Then they receive a 401 Unauthorized response and are prompted to log in again
Given a user logs out
When they click "Logout"
Then their session token is deleted from SQLite and removed from the browser
Additional acceptance criteria:
Tasks
Backend (C++ Daemon):
Frontend (Dashboard):
Configuration:
Database Schema:
Testing:
Secure User Authentication with Session Tokens
AS A network security administrator managing a production monitoring system
I WANT a secure login system with hashed passwords and session tokens stored in a database
SO THAT I can ensure only authorized personnel access the network dashboard, maintain an audit trail of user activity and prevent API credential exposure in client-side code
Acceptance criteria
Given the dashboard is loaded in a browser
When the user is not authenticated
Then they should see a login form (username + password)
Given a user submits valid credentials to
/loginWhen the server validates the bcrypt-hashed password
Then it generates a UUID session token, stores it in SQLite with metadata (user, IP, login timestamp), and returns it to the client
Given a user has a valid session token
When they request
/metricsor other protected endpointsThen the API validates the session token against SQLite and returns data
Given a session token expires (1 hour of inactivity)
When the user tries to access protected endpoints
Then they receive a 401 Unauthorized response and are prompted to log in again
Given a user logs out
When they click "Logout"
Then their session token is deleted from SQLite and removed from the browser
Additional acceptance criteria:
sessionstabletoken,username,created_at,last_activity,ip_addressTasks
Backend (C++ Daemon):
bcrypt-cpporlibbcrypt)/loginPOST endpoint (accepts{"username":"...", "password":"..."})libuuidorboost::uuid)sessionstable schema/logoutPOST endpoint to delete session from SQLite/loginendpoint (track by IP)Frontend (Dashboard):
www/login.htmlor modal overlay)localStorage(not API token)fetchMetrics()to use session token inAuthorization: Bearer <token>headerConfiguration:
userssection tosample-config.yamlwith bcrypt-hashed passwordssession.expiry_secondsconfig option (default: 3600)session.cleanup_interval_secondsconfig option (default: 300)session.retention_daysconfig option (default: 30)Database Schema:
sessionstable:(token TEXT PRIMARY KEY, username TEXT, created_at INTEGER, last_activity INTEGER, ip_address TEXT)last_activityfor efficient cleanup queriesTesting: