#define BCRYPT_HASHSIZE (64) #define RANDBYTES (16) #define COST (12) void gen_random(char *s, const int len) { static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; for (int i = 0; i < len; ++i) { s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; } s[len] = 0; } const char * hathor_crypt(const char * password) { char salt[BCRYPT_HASHSIZE]; char hash[BCRYPT_HASHSIZE]; gen_random(salt, COST); sprintf(hash, "$5$%d$%s", COST, salt ); return crypt(password, hash); }