Skip to content

Instantly share code, notes, and snippets.

@pearcemc
Created October 22, 2010 18:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pearcemc/641064 to your computer and use it in GitHub Desktop.
Save pearcemc/641064 to your computer and use it in GitHub Desktop.
from django.conf import settings #for RECAPTCHA_PRIVATE key
def verify_recaptcha(request):
import urllib, urllib2, re
values = {
"privatekey": settings.RECAPTCHA_PRIVATE,
"remoteip": request.META['REMOTE_ADDR'],
"challenge": request.POST['recaptcha_challenge_field'],
"response": request.POST['recaptcha_response_field'],
}
url = "http://www.google.com/recaptcha/api/verify?%s" % (urllib.urlencode(values))
o = urllib2.urlopen(url)
if re.match("^true", o.readline()): return True
else: return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment