9 * Before calling this function, you should call srandom().
10 * When 2 identical strings are encrypted, they will not return the same
11 * encryption. Also, str does not need to be less than 8 chars as UNIX crypt
12 * says, although it only works on the first 8 characters.
14 WvString
passwd_crypt(const char *str
)
16 static char saltchars
[] =
17 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
18 char salt
[3], *result
;
20 salt
[0] = saltchars
[random() % (sizeof(saltchars
) - 1)];
21 salt
[1] = saltchars
[random() % (sizeof(saltchars
) - 1)];
24 result
= crypt(str
, salt
);
33 * Before calling this function, you should call srandom().
34 * When 2 identical strings are encrypted, they will not return the same
35 * encryption. Also, str does not need to be less than 8 chars as we're
36 * using the glibc md5 algorithm.
38 WvString
passwd_md5(const char *str
)
40 static char saltchars
[] =
41 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
42 char salt
[12], *result
;
48 for (int i
= 3; i
< 11; ++i
)
49 salt
[i
] = saltchars
[random() % (sizeof(saltchars
) - 1)];
53 result
= crypt(str
, salt
);