cybersecurity · beginner · ~20 min
Bitmask flags as a structured error report.
Validate a password against a classic policy, reporting every failed rule at once as a bitmask — a structured error report the caller can act on.
Implement int password_check(const char *pw) that returns a bitmask of failed requirements (0 if the password passes all checks).
pw: a NUL-terminated ASCII password string the grader passes.Returns int: the OR of the bits for each failed rule:
password (case-insensitive)password_check("Tr0ub4dor&3!") -> 0 (passes everything)
password_check("short") -> 27 (1|2|8|16: short, no upper, no digit, no special)
password_check("MyPasswordis123!") & 32 -> nonzero (contains "password")
password search yourself (strcasestr is non-standard).>= correctly: length 12 passes the length rule.Password policies are a balancing act: strong enough to resist common attacks, loose enough to be usable. NIST 800-63B has moved away from forced complexity in favor of length + breached-password checks, but understanding the legacy 'classic' rules is still important for compliance work.
A NUL-terminated ASCII password string pw.
An int bitmask: a bit set for each failed rule, 0 if all pass.
Space is not special. Length rule is < 12. Single pass over the string preferred.
int password_check(const char *pw) { /* TODO */ return 0; }
Treating space as a special char (it usually shouldn't be); using strcasestr (not standard — implement case-insensitive search yourself); using > instead of >= on the length check.
Empty string fails all. 12+ chars with only letters still fails digit and special.
O(strlen).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.