Today i added the google captcha library to one of my clojure projects. To do this you have to add:

[codesyntax lang=“java“]

[net.tanesha.recaptcha4j/recaptcha4j "0.0.8"]

[/codesyntax]

to your projects dependencies.

To your html template add the following code:

[codesyntax lang=“java“]

<div class="form-group">
	
	<script type="text/javascript"
		src="http://www.google.com/recaptcha/api/challenge?k=challenge_key">
	</script>
</div>

[/codesyntax]

And in your clojure code handle the request like this:

[codesyntax lang=“java“]

(defn connectReCaptch [recaptcha_response_field recaptcha_challenge_field]
  (let [reCaptcha (new ReCaptchaImpl)]
    (.setPrivateKey reCaptcha  "private_key")
    (.checkAnswer reCaptcha "your-domain", recaptcha_challenge_field, recaptcha_response_field)))

(.isValid (connectReCaptch recaptcha_response_field recaptcha_challenge_field))

[/codesyntax]

The two arguments are provided by the form that is generated by the captcha js.

Thats it so far 🙂