Skip to main content

Practice ยท 2 of 2

The password checker that fails closed

Implement check_password(pw) returning (ok, problems) โ€” ok True iff ALL rules pass, problems a list of human-readable violation strings in this fixed order: 1. 'must be at least 12 characters' when len(pw) < 12 2. 'must contain an uppercase letter' when no A-Z 3. 'must contain a lowercase letter' when no a-z 4. 'must contain a digit' when no digit 5. 'must not contain whitespace' when any whitespace 6. 'must not be a known breached password' when lowercased in the fixed set {"password123456", "correcthorsebattery", "letmein123456"} An empty password fails rules 1-4 (and rule 5 not, rule 6 not). Non-string input โ†’ ('must be a string',)-style handling: return (False, ['must be a string']).

Difficulty: advanced

Back to lesson: Practice: Authorization & Session Drills