# M5: Setup Authentication - Scoring Rubric ## Acceptance Criteria Scoring Table | Score | Criteria | |-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 0 | Agent failed to implement acceptance criteria:
- No User model created
- Password hashing not implemented (plaintext storage)
- JWT not generated/verified
- Auth endpoints missing or non-functional
- Frontend auth.tsx absent | | 1 | Agent partially implemented acceptance criteria that builds successfully:
- Basic User model but no password hashing
- Single auth endpoint working (register OR login only)
- Token created but not stored/attached properly
- No frontend AuthContext | | 2 | Agent fully implemented acceptance criteria that builds successfully:
- User model with username, password_hash fields
- PBKDF2 password hashing implemented with salt- All three auth pages created (Login.tsx, Register.tsx, SignOut.tsx)- Missing required fields - **1 pt**: User model created but only has id and username
- password_hash field missing - **2 pts**: User model with id, username (unique+indexed), password_hash fields- Plaintext passwords stored - **1 pt**: Weak hashing algorithm (<8 iterations)
- Fixed salt for all users - **2 pts**: PBKDF2 or bcrypt implemented with >=100,000 iterations
Random salt per password (secrets.token_hex) - **3 pts**: Hash format correct (salt$digest)- Sessions not tokenized - **1 pt**: jwt library imported but no encode/decode
- Token creation broken - **2 pts**: create_token() function generates valid JWTDefault dev key present in code - **4 pts**: TOKEN_TTL_SECONDS set to 7 days (604800 seconds)- /api/auth/* routes missing - **1 pt**: Only one endpoint implemented
- Register OR login working, not both - **2 pts**: Both register and login POST endpoints functional
Correct status codes (200, 400, 401) - **3 pts**: Register validates username format (alphanumeric)- useState for username missing - **1 pt**: createContext exists but no provider component
- login/register functions not implemented - **2 pts**: AuthProvider with children prop rendered ready state tracks initialization - **4 pts**: Login calls api.login(), stores token in localStorage- Token never stored client-side - **1 pt**: TOKEN_KEY constant defined but inconsistent
Mixed case keys in storage - **2 pts**: AUTH_TOKEN key used consistently across frontend code- Fetch calls don't include tokens - **1 pt**: api.login() and api.register() functions exist
Basic fetch implementations - **2 pts**: api.me(token) includes Bearer Authorization header
Token passed correctly - **3 pts**: api.logout() clears token from localStorage
Best effort attempt on server logout - **4 pts**: All auth methods error-handled properly
Throw errors on 401/400 responses ### Frontend Auth Pages (Max 6 points) - **0 pts**: No Login/Register pages
- SignOut component missing - **1 pt**: Only Login.tsx created
No registration option - **2 pts**: Login.tsx with username/password form fields- Plaintext passwords or exposed tokens - **1 pt**: Password hashing present but weak algorithm
- <50,000 iterations - **2 pts**: PBKDF2 with correct salt generation
HS256 algorithm used for JWT - **3 pts**: SECRET_KEY configurable via environment variable- Sensitive configs committed - **1 pt**: data/ directory excluded but individual DB files not covered Best practices followed ## Total Possible Score: 46 points ## Evaluation Notes - Partial credit given for incomplete but working implementations (Score 1) - Full credit requires all acceptance criteria met with passing verification (Score 2 minimum) - Higher scores require additional value-add content beyond baseline requirements - Score 0 indicates agent did not attempt the task or security is compromised ## Critical Security Requirements **MUST HAVE for Score >1:** - [ ] Passwords NEVER stored as plaintext - [ ] PBKDF2 with >=100,000 iterations (SHA256) - [ ] JWT uses HS256 algorithm (never none or symmetric without secret) - [ ] HN_SECRET_KEY used for signing tokens - [ ] Token includes exp claim set to 7 days from iat **MUST HAVE for Score >3:** - [ ] AuthContext provides login, register, logout functions - [ ] localStorage persistence with AUTH_TOKEN key - [ ] Session validation on page load (calls /api/auth/me) - [ ] 401 responses for invalid tokens ## Bonus Points Consideration **+1 point** for: - Input validation regex in register endpoint (username: ^[a-zA-Z0-9_]{3,20}$) - Password strength requirements enforced (minimum length, complexity) **+2 points** for: - Error messages don't leak information (e.g., "Invalid credentials" not "User doesn't exist") - Rate limiting placeholder comments in auth endpoints **+3 points** for: - Complete error handling with meaningful user feedback - Protected routes redirect to login (frontend guard) ## Test Scenarios to Verify Score 5 1. **Registration Flow**: - New username + password → creates User record with hashed password - Returns {token, username} in response - Token can be used for /api/auth/me and returns user data 2. **Login Flow**: - Correct credentials → returns valid token - Wrong credentials → 401 error - Non-existent user → 401 error 3. **Session Restoration**: - Page load with stored AUTH_TOKEN → calls /api/auth/me - Valid token → username set in state - Invalid/expired token → localStorage cleared, ready=true 4. **Logout Flow**: - User clicks logout → localStorage.removeItem(AUTH_TOKEN) - Next page load shows logged out state 5. **Token Validation**: - Modified token → 401 on /api/auth/me - Expired token (after 7 days) → 401 error - Missing Authorization header → 401 error