cybersecurity · intermediate · ~15 min · safe pentest lab
Count auth failures in a log.
Count the failed-login lines in an auth log — the primary brute-force indicator.
Implement int failed_logins(const char *log) that returns how many lines contain "Failed password".
log: a NUL-terminated, newline-separated auth-log string baked into the harness.Returns int: the number of lines that contain the substring "Failed password".
log: "Failed password for root\nAccepted password for bob\nFailed password for admin\n"
failed_logins(log) -> 2
Accepted password) are not counted.A NUL-terminated newline-separated auth-log string log.
An int: the count of lines containing "Failed password".
Static buffer only — no real log-file access.
#include <string.h>
int failed_logins(const char *log) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.