Fossil SCM

Add a new more legible ascii-art font to the anonymous login captcha.

drh 2009-08-10 02:52 trunk
Commit b189acfd7b9209ac251e8c22060ce4453c2f41e7
1 file changed +160 -3
+160 -3
--- src/captcha.c
+++ src/captcha.c
@@ -28,11 +28,11 @@
2828
#include <assert.h>
2929
#include "config.h"
3030
#include "captcha.h"
3131
3232
#if INTERFACE
33
-#define CAPTCHA 2 /* Which captcha rendering to use */
33
+#define CAPTCHA 3 /* Which captcha rendering to use */
3434
#endif
3535
3636
/*
3737
** Convert a hex digit into a value between 0 and 15
3838
*/
@@ -70,11 +70,11 @@
7070
0xf8e88f,
7171
0xf8e888,
7272
};
7373
7474
/*
75
-** Render a 32-bit unsigned integer as an 8-digit ascii-art hex number.
75
+** Render an 8-character hexadecimal string as ascii art.
7676
** Space to hold the result is obtained from malloc() and should be freed
7777
** by the caller.
7878
*/
7979
char *captcha_render(const char *zPw){
8080
char *z = malloc( 500 );
@@ -203,11 +203,11 @@
203203
"| _| ",
204204
"|_| ",
205205
};
206206
207207
/*
208
-** Render a 32-bit unsigned integer as an 8-digit ascii-art hex number.
208
+** Render an 8-digit hexadecimal string as ascii arg.
209209
** Space to hold the result is obtained from malloc() and should be freed
210210
** by the caller.
211211
*/
212212
char *captcha_render(const char *zPw){
213213
char *z = malloc( 300 );
@@ -228,10 +228,167 @@
228228
z[k] = 0;
229229
return z;
230230
}
231231
#endif /* CAPTCHA==2 */
232232
233
+#if CAPTCHA==3
234
+static const char *azFont3[] = {
235
+ /* 0 */
236
+ " ___ ",
237
+ " / _ \\ ",
238
+ "| | | |",
239
+ "| | | |",
240
+ "| |_| |",
241
+ " \\___/ ",
242
+
243
+ /* 1 */
244
+ " __ ",
245
+ "/_ |",
246
+ " | |",
247
+ " | |",
248
+ " | |",
249
+ " |_|",
250
+
251
+ /* 2 */
252
+ " ___ ",
253
+ "|__ \\ ",
254
+ " ) |",
255
+ " / / ",
256
+ " / /_ ",
257
+ "|____|",
258
+
259
+ /* 3 */
260
+ " ____ ",
261
+ "|___ \\ ",
262
+ " __) |",
263
+ " |__ < ",
264
+ " ___) |",
265
+ "|____/ ",
266
+
267
+ /* 4 */
268
+ " _ _ ",
269
+ "| || | ",
270
+ "| || |_ ",
271
+ "|__ _|",
272
+ " | | ",
273
+ " |_| ",
274
+
275
+ /* 5 */
276
+ " _____ ",
277
+ "| ____|",
278
+ "| |__ ",
279
+ "|___ \\ ",
280
+ " ___) |",
281
+ "|____/ ",
282
+
283
+ /* 6 */
284
+ " __ ",
285
+ " / / ",
286
+ " / /_ ",
287
+ "| '_ \\ ",
288
+ "| (_) |",
289
+ " \\___/ ",
290
+
291
+ /* 7 */
292
+ " ______ ",
293
+ "|____ |",
294
+ " / / ",
295
+ " / / ",
296
+ " / / ",
297
+ " /_/ ",
298
+
299
+ /* 8 */
300
+ " ___ ",
301
+ " / _ \\ ",
302
+ "| (_) |",
303
+ " > _ < ",
304
+ "| (_) |",
305
+ " \\___/ ",
306
+
307
+ /* 9 */
308
+ " ___ ",
309
+ " / _ \\ ",
310
+ "| (_) |",
311
+ " \\__, |",
312
+ " / / ",
313
+ " /_/ ",
314
+
315
+ /* A */
316
+ " ",
317
+ " /\\ ",
318
+ " / \\ ",
319
+ " / /\\ \\ ",
320
+ " / ____ \\ ",
321
+ "/_/ \\_\\",
322
+
323
+ /* B */
324
+ " ____ ",
325
+ "| _ \\ ",
326
+ "| |_) |",
327
+ "| _ < ",
328
+ "| |_) |",
329
+ "|____/ ",
330
+
331
+ /* C */
332
+ " _____ ",
333
+ " / ____|",
334
+ "| | ",
335
+ "| | ",
336
+ "| |____ ",
337
+ " \\_____|",
338
+
339
+ /* D */
340
+ " _____ ",
341
+ "| __ \\ ",
342
+ "| | | |",
343
+ "| | | |",
344
+ "| |__| |",
345
+ "|_____/ ",
346
+
347
+ /* E */
348
+ " ______ ",
349
+ "| ____|",
350
+ "| |__ ",
351
+ "| __| ",
352
+ "| |____ ",
353
+ "|______|",
354
+
355
+ /* F */
356
+ " ______ ",
357
+ "| ____|",
358
+ "| |__ ",
359
+ "| __| ",
360
+ "| | ",
361
+ "|_| ",
362
+};
363
+
364
+/*
365
+** Render an 8-digit hexadecimal string as ascii arg.
366
+** Space to hold the result is obtained from malloc() and should be freed
367
+** by the caller.
368
+*/
369
+char *captcha_render(const char *zPw){
370
+ char *z = malloc( 600 );
371
+ int i, j, k, m;
372
+ const char *zChar;
373
+
374
+ k = 0;
375
+ for(i=0; i<6; i++){
376
+ for(j=0; j<8; j++){
377
+ unsigned char v = hexValue(zPw[j]);
378
+ zChar = azFont3[6*v + i];
379
+ for(m=0; zChar[m]; m++){
380
+ z[k++] = zChar[m];
381
+ }
382
+ }
383
+ z[k++] = '\n';
384
+ }
385
+ z[k] = 0;
386
+ return z;
387
+}
388
+#endif /* CAPTCHA==3 */
389
+
233390
/*
234391
** COMMAND: test-captcha
235392
*/
236393
void test_captcha(void){
237394
int i;
238395
--- src/captcha.c
+++ src/captcha.c
@@ -28,11 +28,11 @@
28 #include <assert.h>
29 #include "config.h"
30 #include "captcha.h"
31
32 #if INTERFACE
33 #define CAPTCHA 2 /* Which captcha rendering to use */
34 #endif
35
36 /*
37 ** Convert a hex digit into a value between 0 and 15
38 */
@@ -70,11 +70,11 @@
70 0xf8e88f,
71 0xf8e888,
72 };
73
74 /*
75 ** Render a 32-bit unsigned integer as an 8-digit ascii-art hex number.
76 ** Space to hold the result is obtained from malloc() and should be freed
77 ** by the caller.
78 */
79 char *captcha_render(const char *zPw){
80 char *z = malloc( 500 );
@@ -203,11 +203,11 @@
203 "| _| ",
204 "|_| ",
205 };
206
207 /*
208 ** Render a 32-bit unsigned integer as an 8-digit ascii-art hex number.
209 ** Space to hold the result is obtained from malloc() and should be freed
210 ** by the caller.
211 */
212 char *captcha_render(const char *zPw){
213 char *z = malloc( 300 );
@@ -228,10 +228,167 @@
228 z[k] = 0;
229 return z;
230 }
231 #endif /* CAPTCHA==2 */
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233 /*
234 ** COMMAND: test-captcha
235 */
236 void test_captcha(void){
237 int i;
238
--- src/captcha.c
+++ src/captcha.c
@@ -28,11 +28,11 @@
28 #include <assert.h>
29 #include "config.h"
30 #include "captcha.h"
31
32 #if INTERFACE
33 #define CAPTCHA 3 /* Which captcha rendering to use */
34 #endif
35
36 /*
37 ** Convert a hex digit into a value between 0 and 15
38 */
@@ -70,11 +70,11 @@
70 0xf8e88f,
71 0xf8e888,
72 };
73
74 /*
75 ** Render an 8-character hexadecimal string as ascii art.
76 ** Space to hold the result is obtained from malloc() and should be freed
77 ** by the caller.
78 */
79 char *captcha_render(const char *zPw){
80 char *z = malloc( 500 );
@@ -203,11 +203,11 @@
203 "| _| ",
204 "|_| ",
205 };
206
207 /*
208 ** Render an 8-digit hexadecimal string as ascii arg.
209 ** Space to hold the result is obtained from malloc() and should be freed
210 ** by the caller.
211 */
212 char *captcha_render(const char *zPw){
213 char *z = malloc( 300 );
@@ -228,10 +228,167 @@
228 z[k] = 0;
229 return z;
230 }
231 #endif /* CAPTCHA==2 */
232
233 #if CAPTCHA==3
234 static const char *azFont3[] = {
235 /* 0 */
236 " ___ ",
237 " / _ \\ ",
238 "| | | |",
239 "| | | |",
240 "| |_| |",
241 " \\___/ ",
242
243 /* 1 */
244 " __ ",
245 "/_ |",
246 " | |",
247 " | |",
248 " | |",
249 " |_|",
250
251 /* 2 */
252 " ___ ",
253 "|__ \\ ",
254 " ) |",
255 " / / ",
256 " / /_ ",
257 "|____|",
258
259 /* 3 */
260 " ____ ",
261 "|___ \\ ",
262 " __) |",
263 " |__ < ",
264 " ___) |",
265 "|____/ ",
266
267 /* 4 */
268 " _ _ ",
269 "| || | ",
270 "| || |_ ",
271 "|__ _|",
272 " | | ",
273 " |_| ",
274
275 /* 5 */
276 " _____ ",
277 "| ____|",
278 "| |__ ",
279 "|___ \\ ",
280 " ___) |",
281 "|____/ ",
282
283 /* 6 */
284 " __ ",
285 " / / ",
286 " / /_ ",
287 "| '_ \\ ",
288 "| (_) |",
289 " \\___/ ",
290
291 /* 7 */
292 " ______ ",
293 "|____ |",
294 " / / ",
295 " / / ",
296 " / / ",
297 " /_/ ",
298
299 /* 8 */
300 " ___ ",
301 " / _ \\ ",
302 "| (_) |",
303 " > _ < ",
304 "| (_) |",
305 " \\___/ ",
306
307 /* 9 */
308 " ___ ",
309 " / _ \\ ",
310 "| (_) |",
311 " \\__, |",
312 " / / ",
313 " /_/ ",
314
315 /* A */
316 " ",
317 " /\\ ",
318 " / \\ ",
319 " / /\\ \\ ",
320 " / ____ \\ ",
321 "/_/ \\_\\",
322
323 /* B */
324 " ____ ",
325 "| _ \\ ",
326 "| |_) |",
327 "| _ < ",
328 "| |_) |",
329 "|____/ ",
330
331 /* C */
332 " _____ ",
333 " / ____|",
334 "| | ",
335 "| | ",
336 "| |____ ",
337 " \\_____|",
338
339 /* D */
340 " _____ ",
341 "| __ \\ ",
342 "| | | |",
343 "| | | |",
344 "| |__| |",
345 "|_____/ ",
346
347 /* E */
348 " ______ ",
349 "| ____|",
350 "| |__ ",
351 "| __| ",
352 "| |____ ",
353 "|______|",
354
355 /* F */
356 " ______ ",
357 "| ____|",
358 "| |__ ",
359 "| __| ",
360 "| | ",
361 "|_| ",
362 };
363
364 /*
365 ** Render an 8-digit hexadecimal string as ascii arg.
366 ** Space to hold the result is obtained from malloc() and should be freed
367 ** by the caller.
368 */
369 char *captcha_render(const char *zPw){
370 char *z = malloc( 600 );
371 int i, j, k, m;
372 const char *zChar;
373
374 k = 0;
375 for(i=0; i<6; i++){
376 for(j=0; j<8; j++){
377 unsigned char v = hexValue(zPw[j]);
378 zChar = azFont3[6*v + i];
379 for(m=0; zChar[m]; m++){
380 z[k++] = zChar[m];
381 }
382 }
383 z[k++] = '\n';
384 }
385 z[k] = 0;
386 return z;
387 }
388 #endif /* CAPTCHA==3 */
389
390 /*
391 ** COMMAND: test-captcha
392 */
393 void test_captcha(void){
394 int i;
395

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button