WvStreams
strcrypt.cc
1 #include "strutils.h"
2 #ifndef MACOS
3  #include <crypt.h>
4 #endif
5 #include <unistd.h>
6 #include <stdlib.h>
7 
14 WvString passwd_crypt(const char *str)
15 {
16  static char saltchars[] =
17  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
18  char salt[3], *result;
19 
20  salt[0] = saltchars[random() % (sizeof(saltchars) - 1)];
21  salt[1] = saltchars[random() % (sizeof(saltchars) - 1)];
22  salt[2] = 0;
23 
24  result = crypt(str, salt);
25  if (!result)
26  return "*";
27 
28  WvString s(result);
29  return s;
30 }
31 
38 WvString passwd_md5(const char *str)
39 {
40  static char saltchars[] =
41  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
42  char salt[12], *result;
43 
44  salt[0] = '$';
45  salt[1] = '1';
46  salt[2] = '$';
47 
48  for (int i = 3; i < 11; ++i)
49  salt[i] = saltchars[random() % (sizeof(saltchars) - 1)];
50 
51  salt[11] = 0;
52 
53  result = crypt(str, salt);
54  if (!result)
55  return "*";
56 
57  WvString s(result);
58  return s;
59 }
passwd_md5
WvString passwd_md5(const char *str)
Similar to crypt(), but this randomly selects its own salt.
Definition: strcrypt.cc:38
passwd_crypt
WvString passwd_crypt(const char *str)
Similar to crypt(), but this randomly selects its own salt.
Definition: strcrypt.cc:14
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329