1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.captcha.adapters">
4 <title>CAPTCHA Adapters</title>
7 The following adapters are shipped with Zend Framework by default.
10 <sect2 id="zend.captcha.adapters.word">
11 <title>Zend_Captcha_Word</title>
14 <classname>Zend_Captcha_Word</classname> is an abstract adapter that serves as the base
15 class for most other <acronym>CAPTCHA</acronym> adapters. It provides mutators for
16 specifying word length, session <acronym>TTL</acronym>, the session namespace object
17 to use, and the session namespace class to use for persistence if
18 you do not wish to use <classname>Zend_Session_Namespace</classname>.
19 <classname>Zend_Captcha_Word</classname> encapsulates validation logic.
23 By default, the word length is 8 characters, the session timeout is
24 5 minutes, and <classname>Zend_Session_Namespace</classname> is used for persistence
25 (using the namespace "<classname>Zend_Form_Captcha_<captcha ID></classname>").
29 In addition to the methods required by the
30 <classname>Zend_Captcha_Adapter</classname> interface,
31 <classname>Zend_Captcha_Word</classname> exposes the following methods:
37 <methodname>setWordLen($length)</methodname> and
38 <methodname>getWordLen()</methodname> allow you to specify the length of the
39 generated "word" in characters, and to retrieve the current value.
45 <methodname>setTimeout($ttl)</methodname> and
46 <methodname>getTimeout()</methodname> allow you to specify the time-to-live of
47 the session token, and to retrieve the current value. <varname>$ttl</varname>
48 should be specified in seconds.
54 <methodname>setUseNumbers($numbers)</methodname> and
55 <methodname>getUseNumbers()</methodname> allow you to specify if numbers will be
56 considered as possible characters for the random work or only letters would be
63 <methodname>setSessionClass($class)</methodname> and
64 <methodname>getSessionClass()</methodname> allow you to specify an
65 alternate <classname>Zend_Session_Namespace</classname> implementation to
66 use to persist the <acronym>CAPTCHA</acronym> token and to retrieve the
73 <methodname>getId()</methodname> allows you to retrieve the current token
80 <methodname>getWord()</methodname> allows you to retrieve the generated
81 word to use with the <acronym>CAPTCHA</acronym>. It will generate the word for
82 you if none has been generated yet.
88 <methodname>setSession(Zend_Session_Namespace $session)</methodname> allows
89 you to specify a session object to use for persisting the
90 <acronym>CAPTCHA</acronym> token. <methodname>getSession()</methodname> allows
91 you to retrieve the current session object.
97 All word <acronym>CAPTCHA</acronym>s allow you to pass an array of options to the
98 constructor, or, alternately, pass them to
99 <methodname>setOptions()</methodname>. You can also pass a
100 <classname>Zend_Config</classname> object to <methodname>setConfig()</methodname>. By
101 default, the <emphasis>wordLen</emphasis>, <emphasis>timeout</emphasis>, and
102 <emphasis>sessionClass</emphasis> keys may all be used. Each concrete
103 implementation may define additional keys or utilize the options in
109 <classname>Zend_Captcha_Word</classname> is an abstract class and may not be
110 instantiated directly.
115 <sect2 id="zend.captcha.adapters.dumb">
116 <title>Zend_Captcha_Dumb</title>
119 The <classname>Zend_Captch_Dumb</classname> adapter is mostly self-descriptive. It
120 provides a random string that must be typed in reverse to validate. As such, it's
121 not a good <acronym>CAPTCHA</acronym> solution and should only be used for
122 testing. It extends <classname>Zend_Captcha_Word</classname>.
126 <sect2 id="zend.captcha.adapters.figlet">
127 <title>Zend_Captcha_Figlet</title>
130 The <classname>Zend_Captcha_Figlet</classname> adapter utilizes <link
131 linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link> to present
132 a figlet to the user.
136 Options passed to the constructor will also be passed to the <link
137 linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link> object.
138 See the <link linkend="zend.text.figlet"><classname>Zend_Text_Figlet</classname></link>
139 documentation for details on what configuration options are available.
143 <sect2 id="zend.captcha.adapters.image">
144 <title>Zend_Captcha_Image</title>
147 The <classname>Zend_Captcha_Image</classname> adapter takes the generated word and
148 renders it as an image, performing various skewing permutations to make it
149 difficult to automatically decipher. It
150 requires the <ulink url="http://php.net/gd">GD extension</ulink>
151 compiled with TrueType or Freetype support. Currently, the
152 <classname>Zend_Captcha_Image</classname> adapter can only generate
153 <acronym>PNG</acronym> images.
157 <classname>Zend_Captcha_Image</classname> extends
158 <classname>Zend_Captcha_Word</classname>, and additionally exposes the
165 <methodname>setExpiration($expiration)</methodname> and
166 <methodname>getExpiration()</methodname> allow you to specify a maximum
167 lifetime the <acronym>CAPTCHA</acronym> image may reside on the filesystem.
168 This is typically a longer than the session lifetime. Garbage
169 collection is run periodically each time the <acronym>CAPTCHA</acronym> object
170 is invoked, deleting all images that have expired.
171 Expiration values should be specified in seconds.
177 <methodname>setGcFreq($gcFreq)</methodname> and
178 <methodname>getGcFreg()</methodname> allow you to specify how frequently garbage
179 collection should run. Garbage collection will run every
180 <command>1/$gcFreq</command> calls. The default is 100.
186 <methodname>setFont($font)</methodname> and <methodname>getFont()</methodname>
187 allow you to specify the font you will use. <varname>$font</varname>
188 should be a fully qualified path to the font file.
189 This value is required; the <acronym>CAPTCHA</acronym> will throw an
190 exception during generation if the font file has not been specified.
196 <methodname>setFontSize($fsize)</methodname> and
197 <methodname>getFontSize()</methodname> allow you to specify the font size in
198 pixels for generating the <acronym>CAPTCHA</acronym>. The default is 24px.
204 <methodname>setHeight($height)</methodname> and
205 <methodname>getHeight()</methodname> allow you to specify the height in pixels
206 of the generated <acronym>CAPTCHA</acronym> image. The default is 50px.
212 <methodname>setWidth($width)</methodname> and
213 <methodname>getWidth()</methodname> allow you to specify the width in pixels of
214 the generated <acronym>CAPTCHA</acronym> image. The default is 200px.
220 <methodname>setImgDir($imgDir)</methodname> and
221 <methodname>getImgDir()</methodname> allow you to specify the directory for
222 storing <acronym>CAPTCHA</acronym> images. The default is
223 "<filename>./images/captcha/</filename>", relative to the bootstrap script.
229 <methodname>setImgUrl($imgUrl)</methodname> and
230 <methodname>getImgUrl()</methodname> allow you to specify the relative path to
231 a <acronym>CAPTCHA</acronym> image to use for <acronym>HTML</acronym> markup.
232 The default is "<filename>/images/captcha/</filename>".
238 <methodname>setSuffix($suffix)</methodname> and
239 <methodname>getSuffix()</methodname> allow you to specify the filename suffix
240 for the <acronym>CAPTCHA</acronym> image. The default is
241 "<filename>.png</filename>". Note: changing this value will not change the type
242 of the generated image.
248 <methodname>setDotNoiseLevel($level)</methodname> and
249 <methodname>getDotNoiseLevel()</methodname>, along with
250 <methodname>setLineNoiseLevel($level)</methodname> and
251 <methodname>getLineNoiseLevel()</methodname>,
252 allow you to control how much "noise" in the form of random dots and lines the
253 image would contain. Each unit of <varname>$level</varname> produces one random
254 dot or line. The default is 100 dots and 5 lines. The noise is added twice -
255 before and after the image distortion transformation.
261 All of the above options may be passed to the
262 constructor by simply removing the 'set' method prefix and casting
263 the initial letter to lowercase: "suffix", "height", "imgUrl", etc.
267 <sect2 id="zend.captcha.adapters.recaptcha">
268 <title>Zend_Captcha_ReCaptcha</title>
271 The <classname>Zend_Captcha_ReCaptcha</classname> adapter uses <link
272 linkend="zend.service.recaptcha">Zend_Service_ReCaptcha</link>
273 to generate and validate <acronym>CAPTCHA</acronym>s. It exposes the following
280 <methodname>setPrivKey($key)</methodname> and
281 <methodname>getPrivKey()</methodname> allow you to specify the private key to
282 use for the ReCaptcha service. This must be specified during construction,
283 although it may be overridden at any point.
289 <methodname>setPubKey($key)</methodname> and
290 <methodname>getPubKey()</methodname> allow you to specify the public key to use
291 with the ReCaptcha service. This must be specified during construction, although
292 it may be overridden at any point.
298 <methodname>setService(Zend_Service_ReCaptcha $service)</methodname> and
299 <methodname>getService()</methodname> allow you to set and get
300 the ReCaptcha service object.