> Hi... I am using python2.5 with django 0.97 pre on windows xp.I am new
> to this and I have to use captcha... I can't find any source. Can
> anybody help? Thanking you all...
I used this:
http://svn.navi.cx/misc/trunk/pycaptcha/

I've defined my own, customized captcha in a k_captcha.py:

# --- k_captcha.py
# this class just slightly changes default captcha image ImageCaptcha,
You
# may use ImageCaptcha directly
from Captcha.Visual import Text, Backgrounds, Distortions,
ImageCaptcha
from Captcha import Words
import random
from django.conf import settings

dp = settings.CAPTCHA_DATA_PATH
# my own file with captcha words naped 'basic-polish' was used:
basic_polish_restricted = Words.WordList(dp+"basic-polish",
minLength=3, maxLength=8)
fontFactory = Text.FontFactory((16, 22), "vera")

class KGimpy(ImageCaptcha):
    """A relatively easy CAPTCHA that's somewhat easy on the eyes"""
    defaultSize = (150,45)

    def __init__(self, lcode, *args, **kwargs):
        self.lcode = lcode
        super(KGimpy, self).__init__(*args, **kwargs)

    def getLayers(self):
        if self.lcode == 'pl':
            word = basic_polish_restricted.pick()
        else:
            word = Words.defaultWordList.pick()

        self.addSolution(word)
        return [
            random.choice([
                Backgrounds.CroppedImage(),
                Backgrounds.TiledImage(),
            ]),
            Text.TextLayer(word, borderSize=1,
fontFactory=fontFactory),
            Distortions.SineWarp(),
            ]
# /---- k_captcha.py


# ---- views.py
# default implementation uses:
# from Captcha.Visual.Tests import PseudoGimpy
from k_captcha import KGimpy

from django.views.decorators.cache import cache_control
@cache_control(no_cache=True)
def show_captcha(request):
    """ generate captcha image
    """
    response = HttpResponse()
    response['Content-Type'] = "image/png"
    response['Cache-Control'] = "max-age=0"
    response['Expires'] = "-1"
    # default captcha image generator:
    # g = PseudoGimpy()
    lcode = request.LANGUAGE_CODE
    g = KGimpy(lcode=lcode)
    i = g.render()
    i.save(response, "png")
    safe_solutions = [str(hash(s)) for s in g.solutions]
    #store in session
    request.session['captcha'] = safe_solutions
    return response

def check_captcha(data, request):
    """ Verify captcha
    """
    captcha_solutions = request.session['captcha']
    if str(hash(data)) not in captcha_solutions:
        return 0
    return 1
# ---- /views.py

At your page you should have image with a link to show_captcha: <img
src="....../show_captcha" alt="captchaimg" />
After form submission you have to use 'check_captcha' to verify user
input.

There is also nice captcha solution at: http://recaptcha.net/
And search the web for 'django captcha' keywords

--
Maciej Wisniowski


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to