Adobe ColdFusion 8

Example

Enter the following code on the form page:

<!--- Set the length of the text string for the CAPTCHA image. --->
<cfset stringLength=6>
<!--- Specify the list of characters used for the random text string. The following list
    limits the confusion between upper- and lowercase letters as well as between numbers and
    letters. --->
<cfset
    stringList="2,3,4,5,6,7,8,9,a,b,d,e,f,g,h,j,n,q,r,t,y,A,B,C,D,E,F,G,H,K,L,M,N,P,Q,R,S,
    T,U,V,W,X,Y,Z">
<cfset rndString="">
<!--- Create a loop that builds the string from the random characters. --->
<cfloop from="1" to="#stringLength#" index="i">
    <cfset rndNum=RandRange(1,listLen(stringList))>
    <cfset rndString=rndString & listGetAt(stringList,rndNum)>
</cfloop>
<!--- Hash the random string. --->
<cfset rndHash=Hash(rndString)>

<!--- Create the user entry form. --->
<cfform action="captcha2.cfm" method="post">
<p>Please enter your first name:</p>
<cfinput type="text" name="firstName" required="yes">
<p>Please enter your last name:</p>
<cfinput type="text" name="lastName" required="yes">
<p>Please enter your e-mail address:</p>
<cfinput type="text" name="mailTo" required="yes" validate="email">
<!--- Use the randomly generated text string for the CAPTCHA image. Use the tick count as
    the filename for the CAPTCHA image.--->
<p><cfimage action="captcha" fontSize="24" fonts="Times New Roman" width="200" height="50"
    text="#rndString#"></p>
<p>Please type what you see: </p>
<p><cfinput type="text" name="userInput" required="yes" maxlength=6>
<cfinput type="hidden" name="hashVal" value="#rndHash#">
<p><cfinput type="Submit" name ="OK" value="OK"></p>
</cfform>

Enter the following code on the action page:

<!--- Verify whether the text entered by the user matches the CAPTCHA string. --->
<cfif #form.hashval# eq Hash(#form.userInput#)>
    <cfoutput>
    <p>
    Thank you for registering for our online newsletter, #form.firstName# #form.lastName#.
    </p>
    <p>
    A notification has been sent to your e-mail address: #form.mailTo#.
    </p>
        <cfmail from="newsletter@domain.com" to="#form.mailTo#" subject="Newsletter">
        Thank you for your interest in our Newsletter.
        </cfmail>
    </cfoutput>
<cfelse>
    <p>I'm sorry; please try again.</p>
</cfif>