cybersecurity · intermediate · ~15 min · safe pentest lab
Recognize a bcrypt hash by prefix and length.
bcrypt hashes have a distinctive shape:
int is_bcrypt(const char *h);
Return 1 if h begins with $2a$, $2b$, or $2y$ and is exactly 60 characters long; else 0.
A candidate hash string.
1 if bcrypt, else 0.
Both the prefix and the exact length 60 must hold.
#include <stddef.h>
/* 1 if h is a bcrypt hash: prefix $2a$/$2b$/$2y$ and total length exactly 60. */
int is_bcrypt(const char *h){ (void)h; return 0; }
Accepting any $2...$ prefix; ignoring the length requirement.
A 59- or 61-char $2b$... is not bcrypt; $2x$... is not a recognized variant.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.