Skip to content

Java example of Google reCAPTCHA v3 integrated in Java web application

License

Notifications You must be signed in to change notification settings

newsfusion/recaptcha-v3-java-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Recaptcha V3 Java Example

Java example of Google reCAPTCHA v3 integration in a java web application

  • server side: GoogleRecaptcha.java for recaptcha verification
  • client side: see below

Client side part

Add a hidden input field to your web form

<input type="hidden" id="captchatoken" name="captchatoken" size="1" value=""/>

Include Google Recaptcha JavaScript libary

<script src="https://www.google.com/recaptcha/api.js?render=YOUR_PUBLIC_KEY"></script>

Insert small JavaScript that fill hidden recaptcha token input field

<script>
  grecaptcha.ready(function() {
  	grecaptcha.execute('YOUR_PUBLIC_KEY', {action: 'register'}).then(function(token) {
          $('#captchatoken').val(token)
  	});
  });
</script>

Server side verification

After setting up the client side part, now you can verify the recaptcha token from client side on the server. If the user is valid (human) it will return true, if the user is a bot false

GoogleRecaptcha.isValid(captchatoken)

PS: I'm using this in a Play Framework 1 Web Application

About

Java example of Google reCAPTCHA v3 integrated in Java web application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages