Install It: 5 Minutes Application Integration Tutorial
Install It: 5 Minutes Application Integration Tutorial
Install It: 5 Minutes Application Integration Tutorial
Dashboard
2. JCaptcha
3. …
4. How to
5. 5 minutes application integration tutorial
View a printable version of the current page.
Home Log In
FAQ JCaptcha
JCaptcha
Install it
Maven Site
Issue
Tracking Maven2 users
Login Add the following dependency to your project POM
Sign Up
<dependency>
<groupId>com.octo.captcha</groupId>
Page Operations
<artifactId>jcaptcha</artifactId>
Browse Space <version>1.0</version>
</dependency>
Without Maven2
Add jcaptcha-all.jar (provided in bin-distribution) and commons-collection-3.2 or
greater (not provided see commons collection ) to your application class path, ie
in you WEB-INF/lib folder.
Implement a CaptchaService
It must be a singleton
import com.octo.captcha.service.image.ImageCaptchaService;
import
com.octo.captcha.service.image.DefaultManageableImageCaptc
haService;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
super.init(servletConfig);
CaptchaServiceSingleton.getInstance().getImageChallengeFor
ID(captchaId,
httpServletRequest.getLocale());
// a jpeg encoder
JPEGImageEncoder jpegEncoder =
JPEGCodec.createJPEGEncoder(jpegOutputStream);
jpegEncoder.encode(challenge);
} catch (IllegalArgumentException e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_F
OUND);
return;
} catch (CaptchaServiceException e) {
httpServletResponse.sendError(HttpServletResponse.SC_INTER
NAL_SERVER_ERROR);
return;
}
captchaChallengeAsJpeg =
jpegOutputStream.toByteArray();
responseOutputStream.write(captchaChallengeAsJpeg);
responseOutputStream.flush();
responseOutputStream.close();
}
}
And
<servlet-mapping>
<servlet-name>jcaptcha</servlet-name>
<url-pattern>/jcaptcha</url-pattern>
</servlet-mapping>
The form
Provide a form containing the captcha challenge (the image) and an input text for
the response
<img src="/jcaptcha">
<input type='text' name='j_captcha_response' value=''>
Contribute !
Please put some code showing integration with a new framework in a child page of the
Comments (Hide Comments)
hehe, you might want to add a captcha here!
Calling
CaptchaServiceSingleton.getInstance().validateResponseForID(captchaId,
captcha_response);
twice gives me
I am trying to check the response via an ajax service, so may call this a few
times.
Is there a good way to find out what the word should be, so that I don't have to
run validate?
Hi,
I'm trying to create a JSP page to display "the form" section listed above. I have
several questions:
1: Could you write the code into the tutorial for how to instantiate the
CaptchaService on that page? Do I need to create a reference to a bean on that
page? If so, please show me how exactly to write all of the code for that page to
work.
2: how does writing "jcaptcha" for the "img src" in <img src="jcaptcha"> create
an image? I feel like there should be some reference to the CaptchaService to be
able to correctly display an image from the service? Should something else be
written there for me to get it to work?
3: when you say "Handle the post (using a servlet, or whatever)" does that mean
we can just post the form to another JSP page with the validation routine? I'm
not clear what you are referring to.
Hooha!!
It works for me
The implementation described above worked fine for me but I want to use a
different type of image (one that is easier to understand the letters). I
implemented the CaptchaServiceSingleton as follows:
I then create the image as described except using only the user's session id. The
image is created as expected but when I call validateResponseForID, no matter
what the response is (even an empty string), it always returns true. Did I do
something wrong? What could be causing it to work improperly?
Hello Nathan. I have done the same thing and am experiencing the same
problems. Did you ever find a solution to this?
My problem is that when I load the page, I sometimes get the desired image size
and background and sometimes not (in this case, I get the funky 3 color gradient
background)... I guess it is because the engine is initialized with a default captcha
factory? For this reason, I tried to do the following to reset the engine factories:
ImageCaptchaFactory[] captchaFactories =
;
engine.setFactories(captchaFactories);
After that, nothing works anymmore... Any idea on what I should do?
Greetings, Jimmy.
For example:
This was a great post; thank you! I was able to get it working in my application
perfectly. I adjusted the image size and the number of characters to meet my
specific requirements. I just have one question: the text is being pasted in on the
background, right on the left edge. Is there a way to center the text, or at least
to have a left margin?
/**
* @param factories new captcha factories for this
engine
*/
public void setFactories(CaptchaFactory[] factories)
throws CaptchaEngineException {
if (factories == null || factories.length == 0) {
throw new CaptchaEngineException("impossible
to set null or empty factories");
}
ArrayList tempFactories = new ArrayList();
this.factories = tempFactories;
}
Thanks,
Michael
I also failed to implement the customize images using this example. How to get
the customize images or background other than default one. Thanks
Hi Marc
Great article.
Regards
The codec used for JPEG generation will be deprecated in futere releases of JDK.
It should be changed with the following lines:
import javax.imageio.ImageIO;
........
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/png");
//the same id must be used to validate the response,
//the session id is a good candidate!
String captchaId = request.getSession().getId();
// call the ImageCaptchaService getChallenge method
BufferedImage image =
CaptchaServiceSingleton.getInstance().getImageChallengeForID(captchaId,
request.getLocale());
ServletOutputStream os = response.getOutputStream();
//Writing the image to outputstream
ImageIO.write(image, "png", os);
// flush it in the response
os.flush();
os.close();
}
......
}
Please help i need documentation or a tutorial for integrating the sound captcha
functionallity i cannot find anything, it would be nice to have a tutorial like the 5
min app integration using sound captcha.
thanks.
Hi,
I am looking for JCaptcha with sound integration.
It seems JCaptcha is supporting sound. But I don't know how to integrate sound
with JCaptcha.
Anyone please send the steps to integrate JCaptcha with sound.
Adv. thanks,
Hi Eric,
I thought about the same. But if you configure your load balancer to have sticky
sessions, then it's no problem, because the second request containing the
response on the challenge will land in the same application server, hence in the
same JVM. The only problem with this is in the rare case when the first request is
sent to server A, then it crashes, then the second request goes to server B - it
will fail then, of course. But then the user repeats the submit with a different
challenge coming from server B, and it will (hopefully) succeed.
Implementation class
<img
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.
xsd" src="${imageURL}" align="absmiddle" alt="Dynamic
Verification Code" />
in MyPage.java
@Inject private
MyCaptchaService captchaService;
@Inject private RequestGlobals
requestGlobals;
String sessionId =
requestGlobals.getHTTPServletRequest().getSession().getId(
);
if (!
captchaService.isValidUserResponse(verificationCode,
sessionId)) {
form.recordError("Verification code you
entered does not match");
}
I would like to thanks Mr. Dmitry Kudrenko who has posted about extending of
Captcha engine.
Best Regards
Lakshitha Ranasinghe,
Colombo, Sri Lanka.
Hi Lakshitha Ranasinghe,
Can you write addition a tutorial for JCaptcha Integration with Tapestry 4 ? At
present, between Tapestry 4 and Tapestry 5 have very large difference. For
instance, Tapestry 4 doesn't support the StreamResponse interface and other
cleasses/service.
Bao
It worked when I used (JSP + servlet) but will it also work if I implement it on
(HTML + VelocityServlet) ?
Hi guys,
JPEGImageEncoder jpegEncoder =
JPEGCodec.createJPEGEncoder(jpegOutputStream);
jpegEncoder.encode(challenge);
Thankyou,
ravindra
Hi all,
Thankyou,
ravindra
a colleague and i have written an article about GWT, which includes a description
of how to integrate JCaptcha with GWT. The article and the free source code are
at:
http://www.maxant.co.uk/whitepapers.jsp
The paper is called "Enterprise GWT: Combining Google Web Toolkit, Spring and
Other Features to Build Enterprise Applications"
Hi All,
Please can anyone help me to integrate the sound captcha and image captcha in
the struts application.The requirment is letters which are generated in the image
captcha could be listened by sound captcha and also validate the response
submited by user.
Thanks in advance.
Thanks, Biswajit
Bug/feature request –
Atlassian News –
Contact administrators