...
The simplest configuration possible is to declare the following in your Spring context
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean class="com.octo.captcha.service.image.DefaultManageableImageCaptchaService" id="imageCaptchaService"/>
|
...
Showing how to change the default engine, for getting diferent captchas:
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<bean id="captchaEngine" class="com.octo.captcha.engine.image.gimpy.SimpleListImageCaptchaEngine"/>
<bean id="captchaService" class="com.octo.captcha.service.image.DefaultManageableImageCaptchaService"
singleton="true">
<property name="captchaEngine" ref="captchaEngine"/>
</bean>
|
...
There are several Engines pre-configured, but as we want to control configuration, we have to use the GenericCaptchaEngine, which is built with a list of captcha factories (factories are the ?real? producer of captchas)
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="imageEngine" class="com.octo.captcha.engine.GenericCaptchaEngine">
<constructor-arg index="0">
<list>
<ref bean="CaptchaFactory"/>
</list>
</constructor-arg>
</bean>
|
...
- A word generator, to create the text to read.
- A wordToImage, to generate the captcha from the text.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="CaptchaFactory" class="com.octo.captcha.image.gimpy.GimpyFactory" >
<constructor-arg><ref bean="wordgen"/></constructor-arg>
<constructor-arg><ref bean="wordtoimage"/></constructor-arg>
</bean>
|
A WordGenerator creates a text to be read, it can be random, be a common implementation take words from a list, and can make composition to create a text easier to read for a human being. In the example the WordGenerator needs a Dictionnary to get real words from.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<bean id="wordgen" class= "com.octo.captcha.component.word.wordgenerator.DictionaryWordGenerator" >
<constructor-arg><ref bean="filedict"/></constructor-arg>
</bean>
|
A Dictionary provides words, this one reads words from the one provided by default, with almost 6000 english words.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="filedict" class="com.octo.captcha.component.word.FileDictionary" >
<constructor-arg index="0"><value>toddlist</value></constructor-arg>
</bean>
|
...
This example is a bit more complex one; it takes the usual main three components, but also three deformations, to increase the power of captchas. All three are set to none, a component which creates no deformation, see below, and Examples to have more examples of deformations.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="wordtoimage" class="com.octo.captcha.component.image.wordtoimage.ComposedWordToImage" >
<constructor-arg index="0"><ref bean="fontGenRandom"/></constructor-arg>
<constructor-arg index="1"><ref bean="backGenUni"/></constructor-arg>
<constructor-arg index="2"><ref bean="simpleWhitePaster"/></constructor-arg>
</bean>
|
A FontGenerator provide Fonts to a WordToImage, differents fonts increase the difficulties for cracking software using a learning process. This one generates random fonts from a list, and the first two arguments are the minimum size and the maximum size of the font.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<bean id="fontGenRandom" class="com.octo.captcha.component.image.fontgenerator.RandomFontGenerator" >
<constructor-arg index="0"><value>40</value></constructor-arg>
<constructor-arg index="1"><value>50</value></constructor-arg>
<constructor-arg index="2">
<list>
<ref bean="fontArial"/>
</list>
</constructor-arg>
</bean>
|
A font is declared like this :
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="fontArial" class="java.awt.Font" >
<constructor-arg index="0"><value>Arial</value></constructor-arg>
<constructor-arg index="1"><value>0</value></constructor-arg>
<constructor-arg index="2"><value>10</value></constructor-arg>
</bean>
|
The BackgrountGenerator component can be very simple like in the example, single color, or more complex with real picture, or fancy computed shapes. The first two arguments are always, the size (length and height) of the resulting image.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="backGenUni" class="com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator" >
<constructor-arg index="0"><value>300</value></constructor-arg>
<constructor-arg index="1"><value>100</value></constructor-arg>
</bean>
|
The TextPaster, according to his name, pastes the text on the background. This can be done in a simple way, (see example below), or another implementation can paste each character randomly (but still readably), or can double the text to make computers more confused. TextPaster can be even decorated to put perturbations around the text, a component, TextDecorator, is designed for this purpose, see Annexes for some examples. Commons arguments for TextPaster are:
1. Minimal length of the text
2. Maximal length of the text
3. A color generator component to create the text color, see Annexes.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<bean id="simpleWhitePaster" class="com.octo.captcha.component.image.textpaster.SimpleTextPaster" >
<constructor-arg type="java.lang.Integer" index="0">
<value>3</value>
</constructor-arg>
<constructor-arg type="java.lang.Integer" index="1">
<value>5</value>
</constructor-arg>
<constructor-arg type="java.awt.Color" index="2">
<ref bean="colorGreen"/>
</constructor-arg>
</bean>
|
And a color definition:
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solid | xml |
---|
|
<bean id="colorGreen" class="java.awt.Color" >
<constructor-arg index="0"><value>0</value></constructor-arg>
<constructor-arg index="1"><value>255</value></constructor-arg>
<constructor-arg index="2"><value>0</value></constructor-arg>
</bean>
|
...
The arg index1 is the captcha session expering time, in seconds. Next arg especifies the maximun storage size.
Code Block |
---|
| xml |
---|
| xml |
---|
borderStyle | solidxml |
---|
|
<bean id="captchaService" class="com.octo.captcha.service.multitype.GenericManageableCaptchaService">
<constructor-arg index="0"><ref bean="imageEngine"/></constructor-arg>
<constructor-arg index="1"><value>180</value></constructor-arg>
<constructor-arg index="2"><value>180000</value></constructor-arg>
</bean>
|
...