Diff
Not logged in

Differences From:

File src/captcha.c part of check-in [b4a29fac93] - Add an ascii-art captcha for anonymous login. by drh on 2009-08-10 02:29:14. [view]

To:

File src/captcha.c part of check-in [7a2c37063a] - merge trunk into creole branch by bob on 2009-09-22 07:49:39. Also file src/captcha.c part of check-in [b189acfd7b] - Add a new more legible ascii-art font to the anonymous login captcha. by drh on 2009-08-10 02:52:27. [view]

@@ -29,9 +29,9 @@
 #include "config.h"
 #include "captcha.h"
 
 #if INTERFACE
-#define CAPTCHA 2  /* Which captcha rendering to use */
+#define CAPTCHA 3  /* Which captcha rendering to use */
 #endif
 
 /*
 ** Convert a hex digit into a value between 0 and 15
@@ -71,9 +71,9 @@
   0xf8e888,
 };
 
 /*
-** Render a 32-bit unsigned integer as an 8-digit ascii-art hex number.
+** Render an 8-character hexadecimal string as ascii art.
 ** Space to hold the result is obtained from malloc() and should be freed
 ** by the caller.
 */
 char *captcha_render(const char *zPw){
@@ -204,9 +204,9 @@
  "|_|  ",
 };
 
 /*
-** Render a 32-bit unsigned integer as an 8-digit ascii-art hex number.
+** Render an 8-digit hexadecimal string as ascii arg.
 ** Space to hold the result is obtained from malloc() and should be freed
 ** by the caller.
 */
 char *captcha_render(const char *zPw){
@@ -228,8 +228,165 @@
   z[k] = 0;
   return z;
 }
 #endif /* CAPTCHA==2 */
+
+#if CAPTCHA==3
+static const char *azFont3[] = {
+  /* 0 */
+  "  ___  ",
+  " / _ \\ ",
+  "| | | |",
+  "| | | |",
+  "| |_| |",
+  " \\___/ ",
+
+  /* 1 */
+  " __ ",
+  "/_ |",
+  " | |",
+  " | |",
+  " | |",
+  " |_|",
+
+  /* 2 */
+  " ___  ",
+  "|__ \\ ",
+  "   ) |",
+  "  / / ",
+  " / /_ ",
+  "|____|",
+
+  /* 3 */
+  " ____  ",
+  "|___ \\ ",
+  "  __) |",
+  " |__ < ",
+  " ___) |",
+  "|____/ ",
+
+  /* 4 */
+  " _  _   ",
+  "| || |  ",
+  "| || |_ ",
+  "|__   _|",
+  "   | |  ",
+  "   |_|  ",
+
+  /* 5 */
+  " _____ ",
+  "| ____|",
+  "| |__  ",
+  "|___ \\ ",
+  " ___) |",
+  "|____/ ",
+
+  /* 6 */
+  "   __  ",
+  "  / /  ",
+  " / /_  ",
+  "| '_ \\ ",
+  "| (_) |",
+  " \\___/ ",
+
+  /* 7 */
+  " ______ ",
+  "|____  |",
+  "    / / ",
+  "   / /  ",
+  "  / /   ",
+  " /_/    ",
+
+  /* 8 */
+  "  ___  ",
+  " / _ \\ ",
+  "| (_) |",
+  " > _ < ",
+  "| (_) |",
+  " \\___/ ",
+
+  /* 9 */
+  "  ___  ",
+  " / _ \\ ",
+  "| (_) |",
+  " \\__, |",
+  "   / / ",
+  "  /_/  ",
+
+  /* A */
+  "          ",
+  "    /\\    ",
+  "   /  \\   ",
+  "  / /\\ \\  ",
+  " / ____ \\ ",
+  "/_/    \\_\\",
+
+  /* B */
+  " ____  ",
+  "|  _ \\ ",
+  "| |_) |",
+  "|  _ < ",
+  "| |_) |",
+  "|____/ ",
+
+  /* C */
+  "  _____ ",
+  " / ____|",
+  "| |     ",
+  "| |     ",
+  "| |____ ",
+  " \\_____|",
+
+  /* D */
+  " _____  ",
+  "|  __ \\ ",
+  "| |  | |",
+  "| |  | |",
+  "| |__| |",
+  "|_____/ ",
+
+  /* E */
+  " ______ ",
+  "|  ____|",
+  "| |__   ",
+  "|  __|  ",
+  "| |____ ",
+  "|______|",
+
+  /* F */
+  " ______ ",
+  "|  ____|",
+  "| |__   ",
+  "|  __|  ",
+  "| |     ",
+  "|_|     ",
+};
+
+/*
+** Render an 8-digit hexadecimal string as ascii arg.
+** Space to hold the result is obtained from malloc() and should be freed
+** by the caller.
+*/
+char *captcha_render(const char *zPw){
+  char *z = malloc( 600 );
+  int i, j, k, m;
+  const char *zChar;
+
+  k = 0;
+  for(i=0; i<6; i++){
+    for(j=0; j<8; j++){
+      unsigned char v = hexValue(zPw[j]);
+      zChar = azFont3[6*v + i];
+      for(m=0; zChar[m]; m++){
+        z[k++] = zChar[m];
+      }
+    }
+    z[k++] = '\n';
+  }
+  z[k] = 0;
+  return z;
+}
+#endif /* CAPTCHA==3 */
 
 /*
 ** COMMAND: test-captcha
 */