recaptcha

Homepage: https://github.com/fsmunoz/recaptcha

Author: Frederico Munoz

Updated:

Summary

An Emacs Lisp interface to reCAPTCHA

Commentary

This file contains an elisp interface to Google's reCAPTCHA
service; two different areas are covered:

1) reCAPTCHA: verifies that the user as correctly introduced the CAPTCHA
2) reCAPTCHA mailhide: used to encrypt email addresses in webpages, and decrypt them after a successful CAPTCHA

The main entry points are:

recaptcha-html: outputs the HTML code that needs to be included in a webpage to display the CAPTCHA
recaptcha-verify: takes as input the challenge (i.e. what the user wrote) and validates the CAPTCHA
recaptcha-mailhide-html: outputs the HTML to show an email address.

Several supporting functions exist that deal with specific tasks;
the ones considered private adhere to the practice of being
prefixed with recaptcha-- .

The following code can be used to quickly test the code, it is
based on elnode (and thus requires it of course). After evaluating
it http://localhost:8009/recaptcha and http://localhost:8009/mailhide/
are listening, each testing a particular functionality.

(defun root-handler (httpcon)
  (elnode-hostpath-dispatcher httpcon '(("^.*//recaptcha/\\(.*\\)" . recaptcha-handler)
					("^.*//mailhide/\\(.*\\)" . mailhide-handler))))

(elnode-start 'root-handler :port 8009)

(defun recaptcha-handler (httpcon)
  "Demonstration function"
  (elnode-http-start httpcon 200 '("Content-type" . "text/html"))
  (when (elnode-http-param httpcon "recaptcha_response_field")
    ;; Test reCAPTCHA
    (if (recaptcha-verify
	 (process-contact httpcon :host)
	 (elnode-http-param httpcon "recaptcha_challenge_field")
	 (elnode-http-param httpcon "recaptcha_response_field"))
	(elnode-http-return httpcon "OK!")
      (elnode-http-return httpcon (recaptcha-html))))
  (elnode-http-return httpcon (recaptcha-html)))

(defun mailhide-handler (httpcon)
  "Demonstration function"
  (elnode-http-start httpcon 200 '("Content-type" . "text/html"))
  (elnode-http-return httpcon (recaptcha-mailhide-html "bart@example.com" "Bartolomeu Dias")))

Dependencies