reCAPTCHA your Rails Application !

2

CAPTCHA stands for "Completely Automated Public Turing test to tell Computers and Humans Apart". As the acronym suggests, the main reason of using CAPTCHA is to tell computers and humans apart through a challenge-response test used to ensure that the response is not machine generated. CAPTCHA comes in many forms; some are more popular than the others:

    1. Text based CAPTCHAs in which the user sees an image displaying letters or numbers and is asked to type what he sees

    2. Image recognition CAPTCHAs which display some images and ask questions about their content. Microsoft Assira is an example

    3. 3D CAPTCHAs which display complex computer generated 3D graphics scenes and ask about the 3D scene's details and content

Image recoginition and 3D recognition try to impose more difficulty on computer programs that try to break CAPTCHAs.

reCAPTCHA is one of the CAPTCHA efforts. It tries to solve another problem in addition to fighting spam; it tries to improve the process of digitizing books by sending words that cannot be read by computers to the Web in the form of CAPTCHAs for humans to decipher. The question that popped immediately in my mind was how does reCAPTCHA verify the answers if it's using images of words that the computer couldn't really figure out what they were while scanning them. The answer is simple: it displays two words at a time, one word can be easily verified and as for the other word, your solution is taken to be a suggestion for that word. That word is used many times in different CAPTCHAs and eventually many people will suggest the same thing.

Currently, reCAPTCHA is recommended as the official CAPTCHA implementation by the original CAPTCHA creators. This way reCAPTCHA not only helps you in fighting spam, but it also gets you to participate into a good cause like digitizing the world's books.

Using reCAPTCHA in your Rails application is made easy thanks to the reCAPTHCA plugin. This plugin gives you 2 main methods that you can use in your application:

1.recaptcha_tags, which should be used in the view in your form.

2.verify_recaptcha, which should be used in the controllers to verify the user's answer

You should register at reCAPTCHA to get your public and private keys which are required by the plugin. The plugin requires that you define them as Environment variables.

recaptcha_tags accepts an options hash which can define the public key with :public_key, so that it doesn't look in your environment variables.

verify_recaptcha - which uses the private key - initially didn't provide a way for you to pass the private_key.

I've forked the plugin here and modified verify_recaptcha so that it now accepts an options hash - like recaptcha_tags - which allows you to define :private_key, which will be used instead of looking into the environment variables. I sent a pull request to the guys over at http://github.com/ambethia/recaptcha to include my changes. Peter Abrahamsen replied and after a couple of messages we modified the plugin so that we no longer need to set the public and private key in any environment variables.  We also added a toggle to enable/disable the plugin. We can use the plugin as follows now:

Ambethia::ReCaptcha.enabled = true
Ambethia::ReCaptcha.public_key = '0123456789ABCDEF'
Ambethia::ReCaptcha.private_key = '0123456789ABCDEF'

If the toggle is set to false, the recaptcha_tags will return nothing and the verify_recaptcha will always return true meaning that the reCAPTCHA code does nothing, which is what we want in case of disabling it.

Fight spam, help in digitizing books, use reCAPTCHA !

Written By:

 

Comments

1

i can see the code in the master branch of recaptcha plugin in github.com/ambethia about verify_recaptcha having a private_key option. But I don't see the toggle (Ambethia::ReCaptcha.enabled = false/true) or Ambethia::ReCaptcha.private_key way of setting the env variable.

2

@mikong, apparently ambethia didnt pull my changes as he said he would.
Why don't you use my fork if you need that feature immediately?
or better yet, why don't you message ambethia about pulling my change again?

Post a Comment

eSpace podcast Prodcast

RSS iTunes