X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=common%2Fauth.c;h=e2f7407d9cbf8ce69c7b5a6908ceeb424e9d0d5f;hb=d67dd1bf5a247e20141b9907f5a452da73624235;hp=240ac470b6b7774039d75a48ccc807b3eb1d2b3a;hpb=859f2b6bd8846ff685a61eec72e96753a8c956f5;p=blerg.git diff --git a/common/auth.c b/common/auth.c index 240ac47..e2f7407 100644 --- a/common/auth.c +++ b/common/auth.c @@ -388,3 +388,28 @@ int auth_check_token(const char *username, const char *given_token) { return ret; } + +/* Return a 32-bit integer "counter" that will change when the password is + * updated. Used to invalidate password recovery schemes after the password is + * updated. Returns the counter in the "counter" argument, and returns + * true/false on success/failure. */ +int auth_get_counter(const char *username, uint32_t *counter) { + struct auth_v2 auth; + struct MD5Context ctx; + uint8_t md5hash[MD5_DIGEST_SIZE]; + + if (auth_get_data(username, (void *) &auth, sizeof(struct auth_v2)) == 0) + return 0; + + /* There's probably going to be some question about using MD5 here. + * All I really need is to quickly and repeatably scramble some bits. + * MD5 can still do that. */ + MD5Init(&ctx); + MD5Update(&ctx, auth.password, SCRYPT_OUTPUT_SIZE); + MD5Update(&ctx, auth.salt, SCRYPT_SALT_SIZE); + MD5Final((unsigned char *)md5hash, &ctx); + + *counter = ((uint32_t *)md5hash)[0]; + + return 1; +}