Page 1 of 1

Add Captcha in Registration Page

Posted: Fri Aug 02, 2013 6:37 am
by alokranjan
Hi,

As per our requirement,we need to configure captcha on registration page.For this i followed below link

http://doanduyhai.wordpress.com/2012/08 ... -security/

In this tutorial they have configured captcha in login page,Same functionality i have done for registration purpose.

I have some couple of doubts here

1.After creating UsernamePasswordAuthenticationFilter.java where i need to keep this file

2.For B Spring MVC Controller for login page i have changed in registration controller to

@RequestMapping(method=RequestMethod.POST)
public String processRegister(HttpServletRequest request, HttpServletResponse response, Model model,
@ModelAttribute("registrationForm") RegisterCustomerForm registerCustomerForm, BindingResult errors) throws ServiceException {
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey("6LdLfeUSAAAAANrm334ENVbsQtVFuZ6MA5x9xQ9l");

String remoteAddr = request.getRemoteAddr();
String challengeField = request.getParameter("recaptcha_challenge_field");
String responseField = request.getParameter("recaptcha_response_field");
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challengeField, responseField);

if(!reCaptchaResponse.isValid())
{
model.addAttribute("invalidCaptcha", "Captcha Is Invalid");
return "home";
}

return super.processRegister(registerCustomerForm, errors, request, response, model);
}

3. Added code in register.html
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=your_public_recaptcha_key">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=6LdLfeUSAAAAABBYifGvYKEDLjUXH68xy7KXPh6w" height="300" width="500" > </iframe >
<br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge"></input>
</noscript>


4. for III Spring Security configuration Part A)Full XML config and B)Spring Security namespace config

I cant able to identify in which file i need to do this changes.Please let us know if i am doing any thing wrong

Thanks

Re: Add Captcha in Registration Page

Posted: Tue Aug 06, 2013 1:00 am
by ankitpatni
Hi alokranjan,

I guess broadleaf is not having any thing for captcha but same you can do with help of adding custom attribute

just see the URL i hope it will work for you.

http://docs.broadleafcommerce.org/core/current/tutorials/getting-started-tutorials/adding-customer-attribute-tutorial

Thanks & Regards,
Ankit Patni

Re: Add Captcha in Registration Page

Posted: Tue Aug 06, 2013 10:49 am
by alokranjan
Hi ankitpatni,

Thanks for your response

I have gone through the link provided by you.In this tutorial they are adding custom attributes for customer to keep track of customer. Captcha is totally different from this it is used for protecting your website from spam.Here i want to integrate goggle captcha (http://www.google.com/recaptcha) in broadleaf registration page.I want to know for integrating this what changes i need to do and where.

Any solution will be helpfull.

Thanks and Regards
Alok Ranjan

Re: Add Captcha in Registration Page

Posted: Wed Aug 07, 2013 5:29 am
by alokranjan
Hi,

I was able to show recaptcha in registration page by adding below code in registration.html

Code: Select all

<div class="form50">
 <script src="http://api.recaptcha.net/challenge?k="Your_Public_Key"></script>
 <noscript>
    <iframe src="http://api.recaptcha.net/noscript?k=Your_Public_Key"
        height="300" width="500" frameborder="0"></iframe>
        <textarea name="recaptcha_challenge_field" rows="3" cols="40">
    </textarea>
   
</noscript>
<input type="hidden" name="recaptcha_response_field" value="#{manual_challenge}"></input>
</div>


Now i want to validate this field,So what changes i need to do for this.

Thanks and Regards
Alok Ranjan

Re: Add Captcha in Registration Page

Posted: Wed Aug 28, 2013 5:43 am
by JenniferBroodman
I am still in a fix for it's solutions..It is quite difficult to execute..In fact I am unable to find the most prior object for it too.. :) :)