cybersecurity · beginner · ~15 min · safe pentest lab

Count accepted logins

Count successful authentications.

Challenge

Count the successful logins in an auth log — correlating these with failures helps spot a brute force that finally got in.

Task

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

Input

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

Output

Returns int: the number of lines containing the substring "Accepted password".

Example

log: "Accepted password for bob\nFailed password for root\nAccepted password for amy\n"
count_accepted(log)   ->   2

Edge cases

  • Lines without the marker (e.g. Failed 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 "Accepted password".

Constraints

Match the substring "Accepted password". Static buffer only.

Starter code

#include <string.h>

int count_accepted(const char *log) {
    /* TODO */
    return 0;
}

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