Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

crypt.cc

Go to the documentation of this file.
00001 #if !(defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__))
00002 #include <crypt.h>
00003 #endif
00004 #include <stdlib.h>
00005 #include <time.h>
00006 #include <unistd.h>
00007 
00008 #include <string>
00009 
00010 char getsaltchar()
00011 {
00012         int r = (int) (64.0 * rand() / (RAND_MAX + 1.0));
00013         if (r < 26)
00014                 return 'a' + r;
00015         r -= 26;
00016         if (r < 26)
00017                 return 'A' + r;
00018         r -= 26;
00019         if (r < 10)
00020                 return '0' + r;
00021         if (r < 1)
00022                 return '.';
00023         else
00024                 return '/';
00025 }
00026 
00027 int main(int argc, char *argv[])
00028 {
00029         char salt[2];
00030         int i;
00031 
00032         if (argc != 2 || string(argv[1]) == "-?") {
00033                 cerr << "Usage: " << argv[0] << " passwd" << endl;
00034                 exit(1);
00035         }
00036 
00037         srand(time(NULL));
00038         salt[0] = getsaltchar();
00039         salt[1] = getsaltchar();
00040 
00041         cout << "crypt: " << crypt(argv[1], salt) << endl;
00042 }

Generated on Sun Oct 24 21:08:17 2004 for NewsCache by doxygen 1.3.6-20040222