views:

73

answers:

6

How to create simple javascript/jquery client side captcha? How it may be realize, thx.

A: 

What is the point of a client-side CAPTCHA?!?

The whole purpose of CAPTCHA is to prevent the server from responding to requests that are made by non-humans. What are you trying to achieve?

Spam-bots will not be executing your JavaScript. Humans will. Spam-bots will not get annoyed (even if they could). Humans can, and will.

Amadan
A: 

Client-Side captchas do not provide the protection a server-generated captcha would because the server can not check if the solved captcha is solved correctly.

chiborg
A: 

That is not possible.

You could create something that looks like a CAPTCHA, but it would only run when it's not needed, i.e. when the page is shown in a browser. When it's needed it won't run, as the program trying to break in won't run the client side script.

Guffa
"That is not possible." - such a strong phrase, what proves itself wrong time after time
Fabiano PS
@Fabiano: Such a strong phrases are waranted in cases like this. A client side CAPTCHA would actually be worse than nothing at all, as it gives a false sense of security, but offers no real security what so ever.
Guffa
I see your point and agree on your comment. But about *being not possible* likely, isn't right
Fabiano PS
@Fabiano: If you want something that *looks* like a CAPTCHA, it's of course possible to do using client script, but to make one that actually works is not possible.
Guffa
A: 

if your purpose is to simply deflect most bots, you might be able to get away with a simple script that chooses 2 numbers at random and asks user to add them.

Scott Evernden
Ок, but if spam bot use form.Submit() it's validation is not saffely,how i may check condition before form.Submit()If atribut on submit hadles only when member click on button submit
Tamifist
That's exactly what everyone keeps telling you - it is not possible. you can't catch `form.submit()`. And especially you can't catch someone who parses your web-page, constructs a POST request and contacts your server programmatically (without a browser, without JavaScript).
Amadan
+3  A: 

Why don't you use reCAPTCHA ? It's free, very efficient, and provides accessibility functionnalities.

I hope I could be of any use. Regards from France ;)

Squ36
Wait, you are from France? Let me remove my up vote. (just kidding)
Kris Krause
No, because it's dependend of reCapthca server
Tamifist
A: 

here you are ;)

<html>
  <head>
    <title>TestPage</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript">
    var captchaText;
    $(function() {
      var pre = $('#captcha');
      captchaText = pre.text();
      pre.text('');

      var lines = ['', '', '', '', '']
      for (var ixLetter = 0; ixLetter < captchaText.length; ixLetter++)
      { 
        var letter = captchaText.substr(ixLetter, 1);

        var letterLines = letters[letter];
        for (var ix = 0; ix < 5; ix++)
        {
          lines[ix] = lines[ix] + '  ' + letterLines[ix];
        }
      }
      for (var ix = 0; ix < 5; ix++)
      {
        pre.append(lines[ix] + '\n');
      }
    });
    function check() 
    {
      if ($('#captchaCheck').val() == captchaText) 
      {
        alert('you are probably human');
      }
      else 
      {
        alert('you probably made a mistake. Don\'t worry. To err is also human.');
      }
    }
    var letters = {
      h: [
        'HH  HH',
        'HH  HH',
        'HHHHHH',
        'HH  HH',
        'HH  HH'
      ],
      i: [
        'II',
        'II',
        'II',
        'II',
        'II'  
      ]
      // etc
    }        

    </script>
  </head>
  <body>
    <pre id="captcha">hi</pre>
    Please type what you see: <input id="captchaCheck"/> <input type="button" value="Check" onclick="check()"/>
  </body>
</html>
Jan Willem B
This is fun but if you use the real letters to represent the letters what is the point? :P Also consider that he is doing this to avoid bots so the submit button and href of the form should be written on a succesful captcha
Fabiano PS
yes those are TODO's :)
Jan Willem B
@Fabiano: It doesn't matter, because it's just a joke.
Guffa