cybersecurity · intermediate · ~15 min
Enforce a composition policy.
Enforce a classic password composition policy.
Implement int password_ok(const char *pw) that returns 1 only if pw satisfies every rule below, else 0.
pw: a NUL-terminated password string the grader passes.Returns int: 1 if pw is at least 8 characters long AND contains at least one lowercase letter, at least one uppercase letter, and at least one digit; otherwise 0.
password_ok("Abcdef12") -> 1
password_ok("Ab1") -> 0 (too short)
password_ok("Abcdefgh") -> 0 (no digit)
A NUL-terminated password string pw.
An int: 1 if pw is >= 8 chars and has lower, upper, and a digit; else 0.
All four conditions must hold. Single pass over the string is enough.
int password_ok(const char *pw) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.