cybersecurity · intermediate · ~15 min · safe pentest lab

Is it a bcrypt hash?

Recognize a bcrypt hash by prefix and length.

Challenge

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.

Input format

A candidate hash string.

Output format

1 if bcrypt, else 0.

Constraints

Both the prefix and the exact length 60 must hold.

Starter code

#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; }

Common mistakes

Accepting any $2...$ prefix; ignoring the length requirement.

Edge cases to handle

A 59- or 61-char $2b$... is not bcrypt; $2x$... is not a recognized variant.

Background lessons

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