To make this work within Grails, I had to make several tweaks. The following files are required:
- JQuery 1.2+ (I am using version - 1.4.2)
- JQuery UI (I am using version - 1.8.2)
- jquery.simpleCaptcha-0.2.js
- Captcha Images placed in images/captchaImages
- BCrypt.java by Damien Miller
- CaptchaController.groovy (below)
Create a new controller called Captcha. This can really be named anything, but if you do rename it, it will have to be updated in the jquery.simpleCaptcha-0.2.js file or passed in as an option via the javascript.
What this controller does is return a JSON object with the data needed to generate the captcha. The JSON appears like so:
Now we just need to implement this in our GSP file and controller. Suppose we have a page like shown above with a pickup code and the last 4 digits of the persons phone number. With adding our captcha div and required javascript, our GSP would look like this:
Finally, we need to perform the validation on the controller side. The modified authentication action would look like the following:
So there ya go. It's actually pretty easy and customers seem to like choosing an image much more than typing a word that is difficult to read.
Hi.
ReplyDeletereally great idea! Definetly worth remembering!
Hello there, my name is Jordan, author of simpleCaptcha. If you would like me to include your Grails implementation in the release, please send over all files to jquery aht jordankasper d com. Of course, you don't have to, but I'm sure some others will appreciate it.
ReplyDeleteGlad to see it worked out for you!
I actually went a step further and used the generated hash as a "key" for the image in a custom rendering action in my controller, so that an association can't be made between an image URL and the name listed for selection.
ReplyDeleteThe action translates the hash into the "actual" URL of the CAPTCHA image and renders the image. With this, instead of passing the URL of the image in to simpleCaptcha, I can pass my custom URL with the hash as a parameter.
Respect and that i have a keen proposal: What Home Renovation Expenses Are Tax Deductible home renovation companies near me
ReplyDelete