Author: xor
Date: 2008-11-13 23:53:07 +0000 (Thu, 13 Nov 2008)
New Revision: 23546

Modified:
   trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java
Log:
Implement captcha factory based on kaptcha.

Modified: trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java
===================================================================
--- trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java 2008-11-13 
23:52:20 UTC (rev 23545)
+++ trunk/plugins/WoT/introduction/captcha/CaptchaFactory1.java 2008-11-13 
23:53:07 UTC (rev 23546)
@@ -5,8 +5,16 @@
  */
 package plugins.WoT.introduction.captcha;
 
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import plugins.WoT.Identity;
 import plugins.WoT.introduction.IntroductionPuzzle;
 import plugins.WoT.introduction.IntroductionPuzzleFactory;
+import plugins.WoT.introduction.captcha.kaptcha.impl.DefaultKaptcha;
 
 /**
  * First implementation of a captcha factory.
@@ -21,8 +29,19 @@
  */
 public class CaptchaFactory1 implements IntroductionPuzzleFactory {
 
-       public IntroductionPuzzle generatePuzzle() {
-               return null;
+       public IntroductionPuzzle generatePuzzle(Identity inserter, int index) 
throws IOException {
+               ByteArrayOutputStream out = new ByteArrayOutputStream(10 * 
1024);
+               try {
+                       DefaultKaptcha captcha = new DefaultKaptcha();
+                       String text = captcha.createText();
+                       BufferedImage img = captcha.createImage(text);
+                        /* TODO: find out the maximum size of the captchas and 
put it here */
+                       
+                       ImageIO.write(img, "jpg", out);
+                       return new IntroductionPuzzle(inserter, "image/jpeg", 
out.toByteArray(), text, index);
+               }
+               finally {
+                       out.close();
+               }
        }
-
 }

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to