EasyCFM.COM ColdFusion Forums / Good Coding Tips! / JS/CF CAPTCHA system

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: JS/CF CAPTCHA system -- page: 1 2

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

ktaisia
12-31-2006 @ 7:45 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 146
Joined: Jun 2005

I dont know if the tips here are worthy enough for this section but I would like somewhere public to store it as it is a very simpleJS/CF captcha system. I dont know if it fool proof but I created it to use on my site
Just copy and paste into any CFM page and run it:
<!---
A Very Simple JS / CF CAPTCHA system
this is for javascript enabled browsers.
if you want to check on the server for no-js browsers
then set the variables to session variables so you
can move them to the server for checking
--->

<cfset variables.chk1 = RandRange(100,999)>
<cfset variables.chk2 = RandRange(100,999)>
<cfoutput>
     </script language="javascript">// change this tag properly
     function chkCap(a,b){
          if(a.value != b.value){
          alert("Not the same");
          return false;
          }
     }
     </script>
     <form name="myForm" action="" method="post" onsubmit="return chkCap(z#variables.chk1#,z#variables.chk2#);">
     <input type="text" name="z#variables.chk1#" value="#variables.chk1#" readonly="readonly" />&nbsp;
     <input type="text" name="z#variables.chk2#" value="" />&nbsp;
     <input type="submit" value="Check it" />
     </form>
</cfoutput>



nicky2k
02-04-2009 @ 5:11 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

Try using this code:

<cfset captcha_string=RandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",6)>
                 <cfimage action="captcha" text="#captcha_string#" fontsize="24" difficulty="low" width="200" height="37" />

nicky2k
02-04-2009 @ 5:13 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

Forgot to [ut in the RandomString function:

<cfscript>  
function RandomString(CharList,Length)
{
   tmpRndStr="";
   for (i=1; i LE Length; i=i+1)
       tmpRndStr=tmpRndStr &    Mid(CharList,Rand()*Len(CharList)+1,1);
return tmpRndStr;
}
</cfscript>

MIGhunter
02-22-2009 @ 1:58 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

@Nick, I got an error when trying your method.  Can you clarify the code please?

An exception occured while performing the captcha cfimage action.
java.security.AccessControlException: access denied (java.io.FilePermission C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\cfusion\tmpCache\CFFileServlet\_cf_captcha read)


This message was edited by MIGhunter on 2-22-09 @ 2:05 AM

nicky2k
02-22-2009 @ 2:07 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

Are you using CF8 or CF7?

The function below takes a random string and length of the characters you want to display and then produces a random combination of those characters.
<cfscript>  
function RandomString(CharList,Length)
{
   tmpRndStr="";
   for (i=1; i LE Length; i=i+1)
        tmpRndStr=tmpRndStr &   Mid(CharList,Rand()*Len(CharList)+1,1);
return tmpRndStr;
}
</cfscript>

The code below then passes a random string of letters and numbers to display in the CAPTHCA image:
<cfset captcha_string=RandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",6)>

Then the <cfimage> code generates the CAPTCHA image based on the random characters generated:
<cfimage action="captcha" text="#captcha_string#" fontsize="24" difficulty="low" width="200" height="37" />
You can change the attributes of the tag as you wish to fit your page design.

I use this code on this site: http://www.obanya.co.uk/anysitecms.



nicky2k
02-22-2009 @ 2:15 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

If you are using CFMX 6, then you might want to visit www.captchas.net and work with their CF API. The cfimage tag does not work on CF MX 6.

MIGhunter
02-28-2009 @ 3:18 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

I'm using fusionlink.com and they are running CF8 Enterprise edition.  I still get the error.

<cfscript>  
function RandomString(CharList,Length)
{
   tmpRndStr="";
   for (i=1; i LE Length; i=i+1)
        tmpRndStr=tmpRndStr &   Mid(CharList,Rand()*Len(CharList)+1,1);
return tmpRndStr;
}
</cfscript>
<cfset captcha_string=RandomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",6)>
<cfimage action="captcha" text="#captcha_string#" fontsize="24" difficulty="low" width="200" height="37" />


An exception occured while performing the captcha cfimage action.
java.security.AccessControlException: access denied (java.io.FilePermission C:\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF\cfusion\tmpCache\CFFileServlet\_cf_captcha read)


This message was edited by MIGhunter on 2-28-09 @ 3:19 AM

nicky2k
02-28-2009 @ 3:26 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 35
Joined: Jan 2004

Can you confirm that fusionlink.com allows the use of cf_image? They may have blocked the use of this tab.

MIGhunter
02-28-2009 @ 7:48 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

well, I submitted it to fusionlink at the same time just incase.  They said:

Can you point to to the page that you are trying to run this. This may take a bit to resolve. You shouldn't be getting this type of error.

So, I'm going out on a whim and saying it's something on their side.

MIGhunter
03-06-2009 @ 4:32 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 570
Joined: Apr 2006

Ok, got it to work.  Now for the really dumb question, how do I implement it into my form so that it checks the value and does the whole captcha thing?

PAGE: 1 2

Website Designed and Developed by Pablo Varando.