WvStreams
|
00001 #include "strutils.h" 00002 #ifndef MACOS 00003 #include <crypt.h> 00004 #endif 00005 #include <unistd.h> 00006 #include <stdlib.h> 00007 00014 WvString passwd_crypt(const char *str) 00015 { 00016 static char saltchars[] = 00017 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; 00018 char salt[3], *result; 00019 00020 salt[0] = saltchars[random() % (sizeof(saltchars) - 1)]; 00021 salt[1] = saltchars[random() % (sizeof(saltchars) - 1)]; 00022 salt[2] = 0; 00023 00024 result = crypt(str, salt); 00025 if (!result) 00026 return "*"; 00027 00028 WvString s(result); 00029 return s; 00030 } 00031 00038 WvString passwd_md5(const char *str) 00039 { 00040 static char saltchars[] = 00041 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; 00042 char salt[12], *result; 00043 00044 salt[0] = '$'; 00045 salt[1] = '1'; 00046 salt[2] = '$'; 00047 00048 for (int i = 3; i < 11; ++i) 00049 salt[i] = saltchars[random() % (sizeof(saltchars) - 1)]; 00050 00051 salt[11] = 0; 00052 00053 result = crypt(str, salt); 00054 if (!result) 00055 return "*"; 00056 00057 WvString s(result); 00058 return s; 00059 }