Showing posts with label Captcha. Show all posts
Showing posts with label Captcha. Show all posts

Wednesday, March 23, 2011

Integration reCaptcha with Spring MVC

When I was explaining about reCaptcha on my previous entry, I made reference to my little-store example app, which basically has a bunch of frameworks (the idea is implement those technologies that I want to learn or just practice).

What I did is really simple, the first step was adding my new dependency to my POM
Then add to my webApplicationContext.xml my new reCaptcha bean
You must get the keys from the official website by adding your site. On my case I put the keys in a properties file, and then by using spring I loaded that file


Next in my Controller I used my ReCaptcha bean, like this
As you could see, this code populates a variable (reCaptcha) which I'm going to display on my JSP using JSTL:
${requestScope.reCaptcha}
Inside of a HTML FORM

Finally, this is how I validated the confirmation text (you must be expecting these 2 params: recaptcha_challenge_field and recaptcha_response_field)

The only problem I faced was related to my flow (which screen should I display), but besides that the implementation is really straight forward, simple!

Sunday, March 20, 2011

reCaptcha - FREE anti-bot service that helps digitize books

Did you remember one of my entries where I implemented jCaptcha???
If you don't know what I'm talking about this is the entry

Now that we understand each other, just for things of the destiny (¬¬ yeah of course!), I found something about "Digitizing Books One Word at a Time" from Google and how many times you've seen this Captcha.


Actually, you can implement it on the same way with jCaptcha, but you need more customization, at the end it has Pros and Cons both solutions, but as an Architect, I take in consideration 2 main factors:
  • Is your App going to be in a closed environment?? Is it going to have access to Internet?? (One thing is that you can access your app through web and something else is that your Network and Server configuration doesn't allow your app to interact with other websites)
  • Do you want to have full control of your App?? Then you don't want to share anything about your app with any external entity, you don't need external Black Boxes (you can re-invent the wheel for you, can't you?)
For this particular situation, I'd prefer to share something with the world, I mean I don't care if Google knows that I'm using its service, My App can share and cooperate with the rest of the world, because I'm not using critical information (for my purposes: Educational)

Then let's begin...
.
What is reCAPTCHA?
reCAPTCHA is a free CAPTCHA service that protects your site against spam, malicious registrations and other forms of attacks where computers try to disguise themselves as a human; a CAPTCHA is a Completely Automated Public Turing test to tell Computers and Human Apart. reCAPTCHA comes in the form of a widget that you can easily add to your blog, forum, registration form, etc.


In my next entry I'll be implementing this reCaptcha in my little-store app :)
So I'll see how it works and how hard is to implement it (obviously I'll need to install the library on my local Maven Repo) and use Scriptlets "duh!"
But as people say, if life gives you lemons, make lemonade and that's what I'm going to do

Wednesday, March 9, 2011

JCaptcha & Spring MVC

Have you ever heard about Captcha.
Is this familiar?

Now that you remember what I'm talking about, let's begin.
I chose JCaptcha, because I used before with Struts back in Mexico for one of my projects when I was working in Government (SICOSIEM) and it was really useful (but I used a servlet)
Now the idea will be implementing the same project on an existing Spring MVC App, which is really simple :)
First things first!. Get JCaptcha and install it in your Local MVN Repo (version 1.0-all), because if you add as dependency version 1.0, it will not work, due to the lack of some jars on Maven Central Repo.
My Controller which will behave like my old servlet (I just have to create an IMG tag with src="/myAppContext/captcha/captcha.htm")
This is how you have to use it (on my previous jsp I have an input text called "captchaText" which holds the value entered by the user)
This is a minimal configuration (I have the bad habit of splitting all my configurations to make my life easier, on this case I'll call this configuration file "jcaptcha.xml"), if you want to dig deeper, you can explore the official web site and play around with other classes (just look into this package: com.octo.captcha.engine.image.gimpy)
FYI: This is the captcha service I'm injecting in my Controllers
Don't forget adding your new configuration file for JCaptcha in your Spring App Context (this is my web.xml)
If you want to see a more complex ("customized") configuration, you can use see this one (It took me a while to create it - but I used as reference what is on JCaptcha WebSite)