Captcha Module

Last modified by Vincent Massol on 2024/07/05 18:18

cogOffers API to generate Captchas
TypeJAR
Category
Developed by

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Description

Starting with XWiki 10.8RC1, this module has been retired and is no longer bundled by default with XWiki. It has been replaced by the CAPTCHA Application.

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.

Prerequisites & Installation Instructions

Starting with XWiki 10.8RC1, after installing with Extension Manager one of the existing versions (i.e. bundled with XWiki versions older than 10.8RC1) or after manually building the source code for yourself and copying the jar file (and any of its missing dependencies) into your WEB-INF/lib folder, you also need to edit your WEB-INF/struts-config.xml file and add the following Action Mappings lines under the existing <action-mappings> tag:

 ...
<action-mappings>
   ...
  <action path="/imagecaptcha/"
          type="org.xwiki.captcha.internal.DefaultImageCaptchaAction">
  </action>
   ...

Restart your wiki and the installation should be complete.

Get Connected