Author: tyrell
Date: Sun Feb 10 06:54:37 2008
New Revision: 13521

Log:

Minor change. Adding internal documentation.

Modified:
   trunk/mashup/java/modules/www/captcha.jsp

Modified: trunk/mashup/java/modules/www/captcha.jsp
==============================================================================
--- trunk/mashup/java/modules/www/captcha.jsp   (original)
+++ trunk/mashup/java/modules/www/captcha.jsp   Sun Feb 10 06:54:37 2008
@@ -29,8 +29,7 @@
     response.setContentType("image/" + imageFormat);
 
     try {
-        // you can pass in fontSize, width, height via the request
-
+        //It is possible to pass the font size, image width and height with 
the request as well
         Color backgroundColor = Color.gray;
         Color borderColor = Color.black;
         Color textColor = Color.white;
@@ -41,8 +40,8 @@
         int height = paramInt(request, "height", 80);
         int circlesToDraw = 6;
         float horizMargin = 20.0f;
-        float imageQuality = 0.95f; // max is 1.0 (this is for jpeg)
-        double rotationRange = 0.7; // this is radians
+        float imageQuality = 0.95f; // max is 1.0 (for jpeg)
+        double rotationRange = 0.7; // in radians
         BufferedImage bufferedImage = new BufferedImage(width, height, 
BufferedImage.TYPE_INT_RGB);
 
         Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
@@ -50,7 +49,7 @@
         g.setColor(backgroundColor);
         g.fillRect(0, 0, width, height);
 
-        // lets make some noisey circles
+        //Generating some circles for background noise
         g.setColor(circleColor);
         for (int i = 0; i < circlesToDraw; i++) {
             int circleRadius = (int) (Math.random() * height / 2.0);
@@ -66,20 +65,13 @@
         int maxAdvance = fontMetrics.getMaxAdvance();
         int fontHeight = fontMetrics.getHeight();
 
-        // i removed 1 and l and i because there are confusing to users...
-        // Z, z, and N also get confusing when rotated
-        // 0, O, and o are also confusing...
-        // lowercase G looks a lot like a 9 so i killed it
-        // this should ideally be done for every language...
-        // i like controlling the characters though because it helps prevent 
confusion
+        //We are not using certain characters, which might confuse users
         String elegibleChars = 
"ABCDEFGHJKLMPQRSTUVWXYabcdefhjkmnpqrstuvwxy23456789";
         char[] chars = elegibleChars.toCharArray();
 
         float spaceForLetters = -horizMargin * 2 + width;
         float spacePerChar = spaceForLetters / (charsToPrint - 1.0f);
 
-        AffineTransform transform = g.getTransform();
-
         StringBuffer finalString = new StringBuffer();
 
         for (int i = 0; i < charsToPrint; i++) {
@@ -90,8 +82,6 @@
 
             // this is a separate canvas used for the character so that
             // we can rotate it independently
-            int charImageWidth = maxAdvance * 2;
-            int charImageHeight = fontHeight * 2;
             int charWidth = fontMetrics.charWidth(characterToShow);
             int charDim = Math.max(maxAdvance, fontHeight);
             int halfCharDim = (int) (charDim / 2);
@@ -119,11 +109,11 @@
             charGraphics.dispose();
         }
 
-        // let's do the border
+        // Drawing the image border
         g.setColor(borderColor);
         g.drawRect(0, 0, width - 1, height - 1);
 
-        //Write the image as a jpg
+        // Gnerating the jpg
         Iterator iter = ImageIO.getImageWritersByFormatName(imageFormat);
         if (iter.hasNext()) {
             ImageWriter writer = (ImageWriter) iter.next();
@@ -139,7 +129,7 @@
             throw new RuntimeException("no encoder found for jsp");
         }
 
-        // let's stick the final string in the session
+        // Storing the string value contained in the image to the session. The 
verifier will have to get it from there
         request.getSession().setAttribute("captcha", finalString.toString());
 
         g.dispose();

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to