captcha Code using Coldfusion 8 advanced technique

The Captcha Using Coldfusion 8 is quite Easy but what I we want to make it bit diifcult for the user to read using Case Sensitiveness.

Here is how we will do it.

First of all we will list the files we need for the this Captcha Stuff. A captcha.cfm file and a Login.cfm file So here is a very easy and small code which we will make the use o the coldfusion captcha.

Captcha.cfm Code:

	<cfset Str_Lower_Case_Alpha = "abcdefghijklmnopqrstuvwxyz" />
	<!--- Set up available upper case values. This is done by converting the lower case string using "UCase". --->
	<cfset Str_Upper_Case_Alpha = UCase( Str_Lower_Case_Alpha ) />
	<!--- Set up available numbers. --->
	<cfset Str_Numbers = "0123456789" />
	<!--- Make a string that contains our lower case upper case and number values. --->
	<cfset strAll = Str_Lower_Case_Alpha & Str_Upper_Case_Alpha & Str_Numbers />
	<!--- Create the password array of 1-3 dimensions. Index array elements with square brackets: [ ]. --->
	<cfset arrPassword = ArrayNew(1) />
	<!--- Generate the password and put each random value in the password array string. --->
	<!--- Select the random letter from our lower case set. --->
	<cfset arrPassword[ 1 ] = Mid(Str_Lower_Case_Alpha,RandRange( 1, Len( Str_Lower_Case_Alpha ) ), 1 ) />
	<!--- Select the random letter from our upper case set. --->
	<cfset arrPassword[ 2 ] = Mid(Str_Upper_Case_Alpha, RandRange( 1, Len( Str_Upper_Case_Alpha ) ), 1 ) />
	<!--- Select the random number from our number set. --->
	<cfset arrPassword[ 3 ] = Mid(Str_Numbers,RandRange( 1, Len( Str_Numbers ) ),1) />
	<!--- Create rest of the password. --->
	<cfset arrPassword[ 4 ] = Mid(strAll,RandRange( 1, Len( strAll ) ),1) />
	<cfset arrPassword[ 5 ] = Mid(strAll,RandRange( 1, Len( strAll ) ),1) />
	<cfset arrPassword[ 6 ] = Mid(strAll,RandRange( 1, Len( strAll ) ),1) />
	<!--- We don?t always want the first three characters to be of the same order (by type). --->
	<!--- Therefore, let's use the Java Collections utility class to shuffle this array into a "random" order. --->
	<cfset CreateObject( "java", "java.util.Collections" ).Shuffle(arrPassword ) />
	<!--- Join all the characters into a single string. --->
	<!--- We can do this by converting the array to a list and then just providing no delimiters (empty string delimiter). --->
	<cfset strPassword = ArrayToList(arrPassword, "" ) />
	<!--- The password is finished. --->
	<cfset rndString = #strPassword#>
	<cfset rndHash=Hash(#strPassword#)>

 

With a little bit of Modification code Provided by ScandicWeb and we will see what is going on now. Now our login.cfm Page:

	<cfoutput>
	<cfform method="post" action="#cgi.SCRIPT_NAME#" name="adminlogin" id="adminlogin">
	<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td valign="center" align="center">
				<table class="border" border="0" cellpadding="1" cellspacing="2" width="500">
					<tr>
						<td>
							<table border="0" cellpadding="0" cellspacing="1" width="100%">
								<caption>
									Login
								</caption>
								<tr>
									<td colspan="2" class="default" align="center">You aren't logged in or your session has expired.<br/>
									Please enter your Username and Password below and click Login.</td>
								</tr>
							<cfif IsDefined('invalid')>
								<tr>
									<td align="center" colspan="2"><div class="darkred">#trim(invalid)#</div></td>
								</tr>
							</cfif>
								<tr>
									<td colspan="2" align="center"><div id='adminlogin_errorloc' class='error_strings' style='></div></td>
								</tr>
								<tr>
									<td class="default" align="right" width="160"><strong>Username: </strong></td>
									<td width="340" align="left"><cfinput type="text" name="j_username" message="Error! Please Provide username" tooltip="Provide Your Username" required="yes" class="inputstyle" id="j_username" tabindex="1" size="25" maxlength="100"></td>
								</tr>
								<tr>
									<td class="default" align="right" width="160"><strong>Password: </strong></td>
									<td width="340" align="left"><cfinput type="password" name="j_password" message="Error! Please Provide Password" tooltip="Password Required" required="yes" class="inputstyle" id="j_password" tabindex="2" size="25" maxlength="100"></td>								</tr>
								<tr>
									<td class="default"> </td>
									<td align="left">
										<cfinclude template="../captcha/captcha.cfm">
										<cfimage action="captcha" fontSize="25" width="200" height="50" text="#rndString#" 
										fonts="Arial,Verdana,Courier New" difficulty="medium" quality="1"><br>
										Case Sensitive Captcha Match Required</td>
								</tr>
								<tr>
									<td class="default" align="right"><strong>Verify Yourself:</strong>
										<cfinput type="hidden" name="userInput" value="#rndHash#"></td>
									<td align="left"><cfinput type="text" name="regVerifyCaptcha" message="Error! Provide Captcha Value" tooltip="Provide Exact Text as above in Image" required="yes" class="inputstyle" id="regVerifyCaptcha" tabindex="3" size="25" maxlength="10"/></td>
								</tr>
								<tr>
									<td align="right" class="default"> </td>
									<td align="left"><input type="checkbox" name="RememberMe" tabindex="4" value="Yes" <cfif IsDefined("cookie.j_username")> CHECKED</cfif>> Remember Me</td>
								</tr>
								<tr>
									<td align="center"> </td>
									<td align="left"><cfinput type="submit" name="submit" value="Login" class="tinyborder" tabindex="5">
										  
										<cfinput type="reset" name="reset" value="Clear" class="tinyborder" tabindex="6"></td>
								</tr>
							</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</cfform>
	</cfoutput>

So next we will check on the page where we check that is there is a match for the captcha

	<cfif Hash(Form.regVerifyCaptcha) NEQ Form.userInput>
		<cfset invalid = "Error! Captcha Text Mismatching, Try again">
	</cfif>

Here now you have a working captcha Code with Case Sensitive Captcha Login

All ColdFusion Tutorials By Author: Gurpreet Singh Randhawa
  • Validating Multiple Email Addresses.
    The Tutorial is reagarding the checking of the multiple email addresses. This is a server side coding using the ReFind and the Replace Functions.
    Author: Gurpreet Singh Randhawa
    Views: 11,992
    Posted Date: Friday, April 6, 2007
  • How to Map Multiple Markers Using Coldfusion & Google Map

    Hi Guys! You have sen many applications with google maps and coldfusion showing a specific markers on the map. Most use Custom Coldfusion based tag to show markers on the website. That is also true. But here i will simply use the javascript and the XML functionality to show multiple markers.

    Evrything is possible with Custom tag, but suppose your host does not allow you to use any custom tag and then u desperately looking a solution something like. Here is the solution for you.

     Very Basic Coldfusion Code is used and i have explained everything in detail for you better understanding

    So we begin now:


    Author: Gurpreet Singh Randhawa
    Views: 3,409
    Posted Date: Monday, August 24, 2009
  • Styling website with various fonts

    This is a Small tutorial where you can style your website with multiple fonts. Just choose the font from the database. very handy and it can make you website look different. It can be tweeked to many phases. think as gar as you can and make the tweek as good as you can. here i have just provided a base how we can play with fonts and many other things. it has not been tested on railo and bluedragon but i think it will work


    Author: Gurpreet Singh Randhawa
    Views: 2,473
    Posted Date: Thursday, September 24, 2009
  • Banning The website With Simple Technique

    A Complete Banning Tutorial where you can add as many ipaddresses as you can and any request coming from that relevan Ipaddress will block the user from accessig the website contents. Very Basic and very easy to follow Up. Mail Me anytime if you encounter certain issues while making the script to work.

    You can add upto unlimited ipaddresses where you can block any unauthorized access to the website.


    Author: Gurpreet Singh Randhawa
    Views: 2,576
    Posted Date: Thursday, October 22, 2009
  • Podcast Using Coldfusion and XML

    A Complete Way how we can add a fetch a Podcast and display on the website. Very easy with just Simple XML Tags. the Tutorial has been Influenced by various Peoples works and Finally i came Up with this. Check and You will have the Podcast view for your own website.


    Author: Gurpreet Singh Randhawa
    Views: 2,767
    Posted Date: Thursday, October 22, 2009
  • captcha Code using Coldfusion 8 advanced technique

     be using the avacedA Small Code where we will be shuffling the code of captcha to display the 6 random number at a time. The Captcha Build is also a Case-Senstive match and made with a bit difficulty to Judge with a small Thinking.


    Author: Gurpreet Singh Randhawa
    Views: 4,498
    Posted Date: Monday, December 28, 2009
  • Detecting Browsers Using Coldfusion
    A Custom Tag in which you will be able to find out what exactly the user is using and then you can change the CSS File according to that specific browser. I Rec-worked this Custom Tag a bit to make it work more better and include some extra browser. Still the Credit goes to Original Browser whose Name i do not Know Really. You will find the code very Handy as it will help in making your website browser-specific and great look to end Users.
    Author: Gurpreet Singh Randhawa
    Views: 3,597
    Posted Date: Thursday, January 28, 2010
Download the EasyCFM.COM Browser Toolbar!