cybersecurity · intermediate · ~15 min

Validate a username

Enforce an allowlist + length on input.

Challenge

Implement int valid_username(const char *s) returning 1 if s is 1..32 chars and contains only letters, digits, and underscore, else 0.

Starter code

int valid_username(const char *s) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.