Password Strength Tagger
Implement tag_password_strength(password) that returns a strength label. Return "invalid" if the password contains any whitespace. Otherwise, count how many character categories appear: lowercase, uppercase, digit, symbol. Return "strong" only if len >= 12 and at least 3 categories appear. Return "medium" only if 8 <= len <= 11 and at least 2 categories appear. Return "weak" for all remaining valid passwords.
- Whitespace makes the password invalid before any strength rules are applied.
- Character categories are lowercase, uppercase, digit, and symbol.
- A symbol is any non-whitespace ASCII character that is not a lowercase letter, uppercase letter, or digit.
"medium"is limited to passwords with length from 8 through 11 inclusive.- Valid passwords with length >= 12 still return
"weak"unless they have at least 3 categories.
password = "Abcdef12"
"medium"
Length 8, contains uppercase, lowercase, and digits — 3 categories.
password = "Abc 12345"
"invalid"
Contains whitespace.
password = "abcdefgh1234"
"weak"
Length 12, but only lowercase and digit categories appear. It does not qualify as strong, and medium only applies to lengths 8 through 11.
- 0 <= len(password) <= 200
- password may contain any ASCII characters
How would you change the rules so password strength can be configured with custom length thresholds and required category counts?
Keep moving through related backend basics problems and build a stronger search-friendly practice loop around this topic.
View track →