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