Password policy violations
A free easy coding practice problem from security. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.
- Difficulty
- Easy
- Type
- Function
- Topic
- Security
- Languages
- JavaScript, TypeScript or Python
Problem
Check password against the policy and return the codes of the rules it BREAKS, in this fixed order:
- "LENGTH" — fewer than 12 characters
- "UPPER" — no uppercase letter A–Z
- "LOWER" — no lowercase letter a–z
- "DIGIT" — no digit 0–9
- "SYMBOL" — no character other than A–Z, a–z, 0–9 (a space counts as a symbol)
- "REPEAT" — the same character appears 3 or more times IN A ROW (e.g. aaa, 111)
- "USERNAME" — username is non-empty and appears inside password, ignoring case
Return [] when the password breaks no rule. Both strings are printable ASCII (codes 32–126), at most 64 characters.
Function signature
// JavaScript
function passwordViolations(password, username)
// TypeScript
function passwordViolations(password: any, username: any): any
// Python
def password_violations(password, username):Examples
passwordViolations("Tr0ub4dor&3xyz", "alice")→[]passwordViolations("password", "bob")→["LENGTH","UPPER","DIGIT","SYMBOL"]passwordViolations("xXAliceXx!2024", "ALICE")→["USERNAME"]
How checking works
Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.