Captcha Module

Last modified by Thomas Mortagne on 2014/05/31 10:40

cogOffers API to generate Captchas
TypeJAR
Developed by

XWiki Development Team

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise, XWiki Enterprise Manager

Description

Example:

captchaEx2.png

Getting the captcha image

The captcha images are served from yourwiki.com/xwiki/bin/imagecaptcha//.

Note that the extra trailing / is required by the XWiki URL scheme (since the Captcha module is reusing the bin URL type which points to a Document and thus requires space and page name placeholders in the URL) but you can put anything before or after it so the following will output yourwiki.com/xwiki/bin/imagecaptcha/SomeSpace/SomePage which will work:

xwiki.getURL(doc.getDocumentReference(), "imagecaptcha", null)

Verifying the answer

To verify the captcha answer you simply need to get the CaptchaVerifier component and then call isAnswerCorrect on it. For example from Groovy:

import org.xwiki.captcha.CaptchaVerifier;
def verifier = services.component.getInstance(CaptchaVerifier.class, "image")
verifier.isAnswerCorrect(verifier.getUserId(request), userSuppliedAnswer)

JCaptcha uses a unique String to tell different users apart so it knows who should be solving which captcha. This String is gotten from the Request object when the user's browser loads the captcha image and it must be supplied to isAnswerCorrect in order to check the supplied answer against the right stored answer. You can get this String by calling getUserId with the Request object.

For more information, you can read the code for the interface CaptchaVerifier.

What about sound captchas?

Sound captcha support will be added when JCaptcha 2.0 is officially released.

How about implementing your own captcha type?

JCaptcha supports a variety of different types of captchas, you can add a new captcha type to XWiki by copying DefaultImageCaptchaAction but using a different JCaptcha ImageCaptchaService implementation.

You can also add a different captcha type which doesn't use JCaptcha at all, all you have to do is implement CaptchaVerifier. Remember that you will be writing a component so it's a good idea to take a look at the Component Module.

Tags: development
Created by Caleb James DeLisle on 2010/02/03 23:20
    

Get Connected