Thursday, October 31, 2013

Creating a Random Captcha with refresh Option

We all know that creating captcha is not a tough job in ColdFusion. But, one newbie in ColdFsion just asked me to help in creating a random captcha for his application.

I thought to share with others.

I have divided the entire code into three parts.

  1. captcha.cfm - Page where we will display the captcha image.
  2. Util.cfc - It contains a user defined function "generateRandomText" to generate random captcha text.
  3. refreshCaptcha.cfm - Page which will handle AJAX call while refreshing captcha image.

Lets see the "captcha.cfm" below:

Here, in above code I have used "ImageCreateCaptcha" function, which is added in ColdFusion 10 for captcha generation.

Lets see the "Util.cfc"

In this file, I have written a function called "generateRandomText"  for generating captcha string. Logic is very simple, you can modify it according to your requirement.

Next, come to "refreshCaptcha.cfm":

We are making AJAX call to this file which again generates random captcha image and sends to browser for display.

So, this is whole story for generating and refreshing captcha image in ColdFusion!!!

3 comments:

  1. That generateRandomText() function isn't really necessary. I just use createUUID() then reverse and grab the however many chars I need. I suppose I could just do a Right instead of a reverse and left. Anyway, the advantage of your algorithm is that you can control exactly which chars are in the random text. I like to exclude the numbers One and Zero and the letters L for Lima, I for Indigo and O for Oscar. The reason is the 1,L,I and O and 0 are too hard to tell apart, especially in a CAPTCHA. I mean, its not compulsory to use all 26 letters and all 10 digits, so why not reduce the confusion?

    My random text for CAPTCHAS generator is just this:

    ReplyDelete
  2. Use this diet hack to drop 2 lb of fat in just 8 hours

    Well over 160000 women and men are hacking their diet with a simple and SECRET "liquids hack" to drop 1-2lbs each and every night while they sleep.

    It's simple and works with everybody.

    Here are the easy steps for this hack:

    1) Go grab a clear glass and fill it up half the way

    2) And now use this awesome HACK

    you'll become 1-2lbs thinner when you wake up!

    ReplyDelete
  3. This way my buddy Wesley Virgin's tale begins in this SHOCKING and controversial VIDEO.

    As a matter of fact, Wesley was in the army-and shortly after leaving-he discovered hidden, "self mind control" tactics that the CIA and others used to get whatever they want.

    As it turns out, these are the EXACT same methods tons of famous people (especially those who "come out of nowhere") and elite business people used to become wealthy and famous.

    You probably know how you use less than 10% of your brain.

    That's because most of your BRAINPOWER is UNCONSCIOUS.

    Maybe this thought has even taken place IN YOUR very own head... as it did in my good friend Wesley Virgin's head 7 years ago, while riding an unregistered, beat-up trash bucket of a car with a suspended license and on his banking card.

    "I'm very fed up with living check to check! Why can't I become successful?"

    You took part in those questions, right?

    Your own success story is waiting to happen. Go and take a leap of faith in YOURSELF.

    Watch Wesley Virgin's Video Now!

    ReplyDelete

Followers