summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ws2a/gencaptcha.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/ws2a/gencaptcha.c b/ws2a/gencaptcha.c
index 5d1bdb6..8713a1a 100644
--- a/ws2a/gencaptcha.c
+++ b/ws2a/gencaptcha.c
@@ -48,6 +48,17 @@ void createRandomWords(char* buf){
buf[pos] = '\0';
}
+
+unsigned long hash(unsigned char *str){
+ unsigned long hash = 5381;
+ int c;
+
+ while (c = *str++)
+ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+
+ return hash;
+}
+
int main(){
srand(time(NULL));
@@ -58,16 +69,19 @@ int main(){
int barraldis2 = rand()%10;
int arcdis = (rand()%99)+1;
char command[1024];
- sprintf(command,"convert -background white -fill black -pointsize 48 label:\"%s\" \"../ws2a/captchas/%s.png\"",randwords,randwords);
+ unsigned long rhash = hash(randwords);
+ sprintf(command,"convert -background white -fill black -pointsize 48 label:\"%s\" \"../ws2a/captchas/%lu.png\"",randwords,rhash);
system(command);
- sprintf(command,"convert \"../ws2a/captchas/%s.png\" -distort Barrel \"0.0%d 0.0 0.0%d\" \"../ws2a/captchas/%s.png\"",randwords,barraldis1,barraldis2,randwords);
+ sprintf(command,"convert \"../ws2a/captchas/%lu.png\" -distort Barrel \"0.0%d 0.0 0.0%d\" \"../ws2a/captchas/%lu.png\"",rhash,barraldis1,barraldis2,rhash);
system(command);
- sprintf(command,"convert \"../ws2a/captchas/%s.png\" -virtual-pixel White -distort Arc %d \"../ws2a/captchas/%s.png\"",randwords,arcdis,randwords);
+ sprintf(command,"convert \"../ws2a/captchas/%lu.png\" -virtual-pixel White -distort Arc %d \"../ws2a/captchas/%lu.png\"",rhash,arcdis,rhash);
system(command);
+ printf("%lu",rhash);
+ /*
FILE* imgfile;
char filepath[100];
- sprintf(filepath,"../ws2a/captchas/%s.png",randwords);
+ sprintf(filepath,"../ws2a/captchas/%lu.png",hash(randwords));
//printf("Filepath:%s",filepath);
imgfile = fopen(filepath,"rb");
if(imgfile == NULL){