| 1 |
lars |
1 |
<com:TContent ID="body" >
|
|
|
2 |
|
|
|
3 |
<h1>TCaptcha</h1>
|
|
|
4 |
<com:DocLink ClassPath="System.Web.UI.WebControls.TCaptcha" />
|
|
|
5 |
|
|
|
6 |
<p>
|
|
|
7 |
<tt>TCaptcha</tt> displays a <a href="http://en.wikipedia.org/wiki/Captcha">CAPTCHA</a> that can be used to determine if the input is entered by a real user instead of some program. <tt>TCaptcha</tt> displays a token (a string consisting of alphanumeric characters) as an image and the user is expected to repeat the token in a text box. The token image is generated in a way such that it can be recognized by a human being, but not a program.
|
|
|
8 |
</p>
|
|
|
9 |
|
|
|
10 |
<p>
|
|
|
11 |
To use <tt>TCaptcha</tt>, you must enable the PHP GD2 extension with TrueType font support. Unlike other CAPTCHA scripts, <tt>TCaptcha</tt> does not need session or cookie.
|
|
|
12 |
</p>
|
|
|
13 |
|
|
|
14 |
<p>
|
|
|
15 |
The token generated by <tt>TCaptcha</tt> can be configured in several ways. To specify the length of characters in the token, set <tt>MinTokenLength</tt> and <tt>MaxTokenLength</tt>. To use case-insensitive token comparison and generate upper-case-only token, set <tt>CaseSensitive</tt> to false. More advanced users can try to set <tt>TokenAlphabet</tt> to specify which characters may appear in the generated tokens.
|
|
|
16 |
</p>
|
|
|
17 |
|
|
|
18 |
<p>
|
|
|
19 |
The validation of the token is related with two properties: <tt>TestLimit</tt> (defaults to 5 times) and <tt>TokenExpiry</tt> (defaults to 600 seconds). The former specifies how many times a token can be tested with on the server side, and the latter says when a generated token will expire. If the validation fails in any of the two scenarios, a new token will be automatically generated.
|
|
|
20 |
</p>
|
|
|
21 |
|
|
|
22 |
<p>
|
|
|
23 |
To specify the appearance of the generated token image, set <tt>TokenImageTheme</tt> to be an integer between 0 and 63. You may try the following example to see how this value affects the generated token image. The size of the generated token image is determined by <tt>TokenFontSize</tt>. In particular, the image width is proportional to the font size. You may also set <tt>Width</tt> to scale the generated image to your desired size, but the scaled image may not look good. By setting <tt>ChangingTokenBackground</tt> to true, the image background of the token will be variating even though the token is the same during postbacks.
|
|
|
24 |
</p>
|
|
|
25 |
|
|
|
26 |
<p>
|
|
|
27 |
Upon postback, user input can be validated by calling the method <tt>TCaptcha.validate()</tt>. More easily, you can use a <tt>TCaptchaValidator</tt> to automate the validation work for you. The <tt>TCaptchaValidator</tt> has the additional benefit of being able to validate the user input on the client-side. By default, a generated token will remain unchanged during postbacks. A new token can be generated by calling <tt>TCaptcha.regenerateToken()</tt> manually.
|
|
|
28 |
</p>
|
|
|
29 |
|
|
|
30 |
<p>
|
|
|
31 |
The following template shows a typical use of the <tt>TCaptcha</tt> control:
|
|
|
32 |
</p>
|
|
|
33 |
<com:TTextHighlighter Language="prado" CssClass="source">
|
|
|
34 |
<com:TCaptcha ID="Captcha" />
|
|
|
35 |
<com:TTextBox ID="Input" />
|
|
|
36 |
<com:TCaptchaValidator CaptchaControl="Captcha"
|
|
|
37 |
ControlToValidate="Input"
|
|
|
38 |
ErrorMessage="You are challenged!" />
|
|
|
39 |
</com:TTextHighlighter>
|
|
|
40 |
|
|
|
41 |
<com:RunBar PagePath="Controls.Samples.TCaptcha.Home" />
|
|
|
42 |
|
|
|
43 |
<div class="last-modified">$Id: Captcha.page 2184 2007-08-30 16:18:16Z xue $</div></com:TContent>
|