viewing paste Unknown #252 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/** Parses a password.
 * This routine can parse a pass that has a salt (new as of unreal 3.2.1)
 * and will set the 'salt' pointer and 'hash' accordingly.
 * RETURN VALUES:
 * 1 If succeeded, salt and hash can be used.
 * 0 If it's a password without a salt ('old'), salt and hash are not touched.
 */
static int parsepass(char *str, char **salt, char **hash)
{
static char saltbuf[MAXSALTLEN+1], hashbuf[MAXHASHLEN+1];
char *p;
int max;
 
    /* Syntax: $<salt>$<hash> */
    if (*str != '$')
        return 0;
    p = strchr(str+1, '$');
    if (!p || (p == str+1) || !p[1])
        return 0;
 
    max = p - str;
    if (max > sizeof(saltbuf))
        max = sizeof(saltbuf);
    strlcpy(saltbuf, str+1, max);
    strlcpy(hashbuf, p+1, sizeof(hashbuf));
    *salt = saltbuf;
    *hash = hashbuf;
    return 1;
}
Viewed 761 times, submitted by Guest.