]> andersk Git - mod-vhost-ldap.git/blob - encrypt.c
Merge branch 'upstream'
[mod-vhost-ldap.git] / encrypt.c
1 #include <stdio.h>
2 #include <time.h>
3 #include <crypt.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 static void to64(char *s, unsigned long v, int n)
9 {
10     static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
11     while (--n >= 0) {
12        *s++ = itoa64[v&0x3f];
13         v >>= 6;
14     }
15 }
16
17 static char *htenc(const char *clearpasswd) {
18         char *res;
19         char salt[9];
20         (void) srand((int) time((time_t *) NULL));
21         to64(&salt[0], rand(), 8);
22         salt[8] = '\0';
23         res = crypt(clearpasswd, salt);
24     return res;
25 }
26
27 int main() { 
28     char *orig = "abcd";
29     printf("Orig: |%s| \n", orig);
30     char *enc = htenc(orig);
31     printf("Enc: |%s| \n", enc);
32         return 1;
33
34 }
35
36
This page took 0.082265 seconds and 5 git commands to generate.