cybersecurity · intermediate · ~15 min
Defence-in-depth — local heuristics never replace a proper password policy and hashing scheme.
Flag obviously weak passwords using a few simple heuristics (a teaching aid, not a real policy).
Implement int is_weak_password(const char *p) that returns 1 if the password is weak by any of these rules, otherwise 0. No main — the grader calls it.
Weak if any of:
password, 123456, qwerty, letmein.p: a NUL-terminated candidate password.
1 if the password is weak by any rule above, 0 otherwise.
is_weak_password("abc") -> 1 (too short)
is_weak_password("aaaaaaaa") -> 1 (all same)
is_weak_password("12345678") -> 1 (all digits)
is_weak_password("password") -> 1 (common)
is_weak_password("Tr0ub4dor!") -> 0
0.A NUL-terminated candidate password p.
1 if weak by any rule (short, all-same, all-digit, common), else 0.
Heuristic teaching aid only, not a real password policy.
#include <string.h>
int is_weak_password(const char *p) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.