cybersecurity · intermediate · ~15 min

Is the password strong enough?

Enforce a composition policy.

Challenge

Enforce a classic password composition policy.

Task

Implement int password_ok(const char *pw) that returns 1 only if pw satisfies every rule below, else 0.

Input

  • pw: a NUL-terminated password string the grader passes.

Output

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.

Example

password_ok("Abcdef12")   ->   1
password_ok("Ab1")        ->   0   (too short)
password_ok("Abcdefgh")   ->   0   (no digit)

Edge cases

  • A password missing any one of the three character classes fails.
  • Exactly 8 characters meets the length rule.

Input format

A NUL-terminated password string pw.

Output format

An int: 1 if pw is >= 8 chars and has lower, upper, and a digit; else 0.

Constraints

All four conditions must hold. Single pass over the string is enough.

Starter code

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.