Esempio n. 1
0
/*
 * encode_puid
 *
 * Encode PUID based on aClient.
 */
static const char *encode_puid(aClient *client)
{
	static char buf[HOSTLEN + 20];

	/* create a cookie if necessary (and in case getrandom16 returns 0, then run again) */
	while (!client->sasl_cookie)
		client->sasl_cookie = getrandom16();

	snprintf(buf, sizeof buf, "%s!%d.%d", me.name, client->slot, client->sasl_cookie);

	return buf;
}
Esempio n. 2
0
void generatePassCode(char passcode[PASSCODELEN])
{
    int idx, min = 1, max = 62;
    int chars[] =
        { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
        'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
        'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
        'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
        'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
    };

    for (idx = 0; idx < 9; idx++) {
        passcode[idx] =
            chars[(1 +
                   (int) (((float) (max - min)) * getrandom16() /
                          (65535 + 1.0)) + min)];
    }

    passcode[idx] = '\0';
}