Add Captcha in Registration Page
Posted: Fri Aug 02, 2013 6:37 am
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
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