technovelty

weblog of Ian Wienand

RSS  |  technovelty home  |  page of ian  |  ian@wienand.org

JavaScript Captcha

Comment spam recently started annoying me, again. Even though it only takes a few clicks to kill, some crappy robot is still taking up my time. Archreality has a nice little JavaScript based Captcha which has the potential to be completely useless as you can see if you click here.

However, I think I've managed to plug it into PyBlosxom and have it be useful. The trick was to make the form submission write a hidden field value in the form with a password after passing the Captcha test.

So, you set up your form like this


<form action="$base_url/$file_path.html" method="post"
name="comments_form" id="comments_form"
onsubmit="try {
           var myValidator = validate_comments_form; 
          } catch(e) { return true; } 
         return myValidator(this);
         "
>
 ... blah ...
 <input type="hidden" name="secret" value="" />
 ... blah ...
</form>

Then in validate_comments_form do something like

function validate_comments_form(frm) {

  captcha = jcap();
  if ( captcha  ) {
        frm.elements['secret'].value = "you_may_pass";
  }
  return captcha;
}

Then, finally modify comments.py from PyBlosxom to check for this value in cb_prepare.

def cb_prepare(args):
    ... somewhere near the top ...
    #captcha
    if (not form.has_key('secret')):
        return False
    if (form['secret'].value != 'you_may_pass'):
        return False

Now, if the spammer is human they will pass anyway, so we don't have to worry about that. Any bot stupidly submitting the form won't have filled out the secret key, so will get dropped. If the bot somehow interprets the javascript, then it's going to have to have enough logic to somehow parse the code and realise it needs to put in that secret value for anything to happen. If your bot can do that then I'm willing to let your spam remain.

I don't like the fact that these things lock out people without great eyesight. I don't see why a alt tag with "Put the value blah into the next box" wouldn't be sufficient, but currently it writes the image in with javascript so I don't know how that would work with a screen reader. In the todo list...

posted at: Thu, 30 Mar 2006 23:23 | in /code/weblog | permalink | add comment (102 others)

Posted by jen at Sat Sep 30 09:22:28 2006

hmm, does this really work?

Posted by a at Sat Oct 21 00:52:37 2006

aaa

Posted by jk at Thu Jul 31 18:43:17 2008

hjkhjk

Posted by dd at Wed Aug 13 19:56:45 2008

dd

Posted by dsaf at Wed Aug 13 19:58:12 2008

ee23222

Posted by dsaf at Wed Aug 13 20:11:30 2008

ee23222

Posted by jaya at Mon Aug 18 22:13:47 2008

hai

Posted by kjjkljl;kjkl at Thu Aug 21 10:55:28 2008

comemments

Posted by dfgdg at Wed Sep 10 04:58:37 2008

fdgdgfgdfg

Posted by sdf at Fri Sep 26 17:52:05 2008

sdf

Posted by asdf at Fri Oct 3 06:25:39 2008

asdf

Posted by sdf at Fri Oct 3 06:25:53 2008

asdf

Posted by sdf at Sun Oct 5 10:49:59 2008

sdf

Posted by sdfdsf at Sun Oct 5 10:50:30 2008

dsfsdf

Posted by kkjkl at Sat Oct 18 12:35:35 2008

nkkljklj

Posted by kkjkl at Sat Oct 18 12:35:40 2008

nkkljklj

Posted by jaja at Mon Nov 10 20:21:41 2008

check

Posted by dsdsdsdfdfdfdf at Thu Dec 25 20:09:03 2008

sdf dff sdfsddfdd sfsd sdf sdf

Posted by ddddddddddddddddddddddddddddddd at Thu Dec 25 20:09:52 2008

ddddddddddddddddddddddddddddddd

Posted by sdfgh at Sun Jan 4 13:25:43 2009

wdgh

Posted by asdf at Sun Jan 4 13:26:02 2009

asdf

Posted by dfd at Mon Jan 5 03:53:52 2009

dfd

Posted by ds at Thu Jan 8 03:47:40 2009

asd

Posted by ds at Thu Jan 8 03:52:03 2009

asd

Posted by ds at Thu Jan 8 03:52:18 2009

asd

Posted by ad at Mon Feb 2 22:03:55 2009

33

Posted by e at Tue Feb 3 04:02:04 2009

e

Posted by test at Sun Feb 8 18:57:49 2009

test

Posted by test at Sun Feb 8 18:58:13 2009

test

Posted by test at Sun Feb 15 11:38:38 2009

test

Posted by juan valdez at Wed Feb 18 11:47:28 2009

meh, seee

Posted by fg at Thu Feb 19 02:03:31 2009

sdf

Posted by blah at Thu Feb 19 02:04:08 2009

blah

Posted by 4 at Fri Feb 27 22:36:20 2009

3

Posted by 4 at Fri Feb 27 22:36:22 2009

3

Posted by Testing at Tue Mar 24 16:07:37 2009

Testing the captcha

Posted by JIm at Tue Mar 31 07:50:12 2009

Testing

Posted by Jim at Tue Mar 31 07:50:34 2009

testing

Posted by Joe at Tue Mar 31 07:51:29 2009

Doesn't seem to work!

Posted by Bob at Wed Apr 1 04:32:07 2009

Does it work?

Posted by Bob at Wed Apr 1 04:32:28 2009

Does it work?

Posted by Bob at Wed Apr 1 04:32:38 2009

Does it work?

Posted by ole at Thu Apr 2 06:44:47 2009

nice!

Posted by fdsafsd at Thu Apr 9 22:06:32 2009

fsdafafdsf

Posted by asdf at Thu Apr 9 22:06:47 2009

asdf

Posted by abcd hhh at Wed Apr 15 01:50:25 2009

Hi..

nice script..

good one..

Posted by fsdgsd g at Fri May 15 13:37:53 2009

segsdgsdgsdfhd

Posted by sdfsdvsd at Fri May 15 14:00:24 2009

cxvxcvxcvxcv

Posted by sdfsdf at Fri May 15 14:00:59 2009

sdfsdfsdf

Posted by casininio at Tue Jun 9 11:37:21 2009

casininio

Posted by ami at Thu Jul 30 21:09:06 2009

hmm k good

Posted by dfdgfhg at Fri Jul 31 12:54:12 2009

dtrytry

Posted by x at Tue Aug 18 20:07:34 2009

hdfg

Posted by wer at Wed Aug 19 22:55:07 2009

ewrwerwerwr

Posted by a at Thu Aug 20 07:44:01 2009

aa

Posted by utut at Thu Sep 3 16:08:45 2009

ytutyu

Posted by oiuo at Thu Sep 3 16:09:03 2009

ouo

Posted by Siala at Thu Sep 3 22:05:19 2009

dfkqsdhkl azed zd zeo

Posted by hh at Sat Sep 26 12:49:45 2009

hjjjkkjkj

Posted by dfadsfa at Wed Sep 30 19:05:31 2009

asdfasf

Posted by vxc at Fri Oct 23 02:01:38 2009

vxcvxc

Posted by rrr123 at Fri Oct 23 02:02:06 2009

gdfg

Posted by gg at Fri Oct 23 02:03:22 2009

ghhg

Posted by asdsad at Sat Nov 7 18:28:15 2009

asdsad

Posted by sdf at Tue Nov 10 00:47:54 2009

sdf

Posted by ff at Wed Nov 11 06:22:58 2009

ff

Posted by Joe Mama at Tue Nov 24 06:39:01 2009

Yo momma

Posted by fgsrdwduissidisdissdsd at Wed Nov 25 13:33:59 2009

gruheuhehowehwroewrehwruehwroehowrroehrehr

Posted by sdfs at Sun Dec 6 19:58:49 2009

fsdfsdfsdfs

Posted by sdfs at Sun Dec 6 19:59:01 2009

fsdfsdfsdfs

Posted by sdfs at Sun Dec 6 19:59:05 2009

fsdfsdfsdfs

Posted by sdfs at Sun Dec 6 19:59:10 2009

fsdfsdfsdfs

Posted by rtr at Mon Dec 21 20:53:55 2009

fgfgfd

Posted by adf at Thu Jan 7 06:22:09 2010

asdfasdfasd

Posted by hjhj at Thu Jan 7 20:11:59 2010

ghjghj

Posted by dfgdfg at Thu Jan 7 20:12:13 2010

dfgdg

Posted by fffff at Fri Feb 5 17:56:54 2010

fffff

Posted by oooppoooopopopo at Wed Feb 17 19:31:55 2010

pooppopopooppopopoooppo

Posted by oooppoooopopopo at Wed Feb 17 19:32:37 2010

,,.,,.,.,.,.,.,.,.,.,.,..,,...,,.,.,.,.,.,..,.,..,..,,....,,. testing 123 testing 123 ,.,.,,.,.,.,.,.,.,.,.,.,..,.,.,..,..,.

Posted by farhan at Mon Feb 22 23:29:08 2010

no

Posted by fsdfasdfasdfasdfasdfas at Thu Feb 25 01:11:01 2010

asdfasdfasdfasdfa sdfas

Posted by Guillermo Calvetty at Thu Feb 25 01:11:45 2010

Espero que funcion

Posted by Guillermo Calvetty at Thu Feb 25 01:11:49 2010

Espero que funcion

Posted by g at Mon Mar 1 09:38:18 2010

sfsf

Posted by dfsf at Mon Mar 1 19:58:00 2010

fasdfasdfasd

Posted by vsvjsfsfh at Tue Mar 2 10:48:22 2010

kdjvjd;jd;j;d;

Posted by Punil at Tue Mar 2 10:49:37 2010

shfjklhfsfh

Posted by sadf at Tue Mar 16 11:13:35 2010

fasdf

Posted by sssss at Fri Mar 19 15:20:17 2010

ddddd

Posted by sssss at Fri Mar 19 15:30:49 2010

ddddd

Posted by sdfasdfa at Thu Apr 1 11:38:25 2010

sadffffffffffff

Posted by sdfasdfasdf at Thu Apr 1 11:39:13 2010

abcdefghijklmonopqrstuvwxyz

Posted by sdfsdfsd at Thu Apr 1 17:50:57 2010

sfdsdfsdfsd

Posted by jghmhukghumkgtk at Tue Apr 6 07:00:47 2010

gjnm ,jnbhv,ugj

Posted by fsgsfgsfgsg at Fri Apr 9 20:40:15 2010

sdgsdgsgsg

Posted by dfgsdfg at Wed Apr 21 05:23:12 2010

sdfgsdfgsdfgdfg

Posted by Keith Rocks at Wed Apr 21 05:24:02 2010

Keith is the man!

Posted by dobbin at Thu Apr 22 20:58:33 2010

Hello World

Posted by dgfdgd at Wed Apr 28 18:37:12 2010

fgdgd

Posted by dfg at Tue Jul 13 01:29:32 2010

gf

Posted by sirisha at Fri Aug 6 03:36:58 2010

kkki

Posted by zzzz at Tue Aug 10 21:29:58 2010

test

Add a comment
*Name
*Email (not shown)
Website
*Comment:
Anti-spam:
* denotes required field

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.