cybersecurity · intermediate · ~15 min · safe pentest lab

Count failed logins

Count auth failures in a log.

Challenge

Count the failed-login lines in an auth log — the primary brute-force indicator.

Task

Implement int failed_logins(const char *log) that returns how many lines contain "Failed password".

Input

  • log: a NUL-terminated, newline-separated auth-log string baked into the harness.

Output

Returns int: the number of lines that contain the substring "Failed password".

Example

log: "Failed password for root\nAccepted password for bob\nFailed password for admin\n"
failed_logins(log)   ->   2

Edge cases

  • Lines without the marker (e.g. Accepted password) are not counted.

Rules

  • Static buffer only — no real log-file access.

Input format

A NUL-terminated newline-separated auth-log string log.

Output format

An int: the count of lines containing "Failed password".

Constraints

Static buffer only — no real log-file access.

Starter code

#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.