Warning: Table './db79366_designmess/sessions' is marked as crashed and should be repaired query: SELECT u.*, s.* FROM users u INNER JOIN sessions s ON u.uid = s.uid WHERE s.sid = '15c9adbf56f05cc73f1f1f6b550d18ab' in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc on line 128

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 1037

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 636

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 637

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 638

Warning: Cannot modify header information - headers already sent by (output started at /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/database.mysqli.inc:128) in /nfs/c05/h04/mnt/79366/domains/designmess.com/html/includes/bootstrap.inc on line 639
Use Mouse Gestures for Captchas and Email Protection | [field_tutorial_category-term] | Designmess

Use Mouse Gestures for Captchas and Email Protection

Submitted by on

Getting Started

For starters, lets start by opening a text editor of your choice and creating a file called index.html

For this tutorial, you will need to download three javascript files: jQuery, Fancy Gestures, and Walter Zorn’s VectorGraphics Library

Include these files like so in the head section.

  1. <script type="text/javascript" src="wz_jsgraphics.js"></script>
  2. <script type="text/javascript" src="jquery.js"></script>
  3. <script type="text/javascript" src="jquery.fancygestures.js"></script>

Create a Gesture

Good. Now that all the files are included, we can edit the script for Fancy Gestures. Don't worry, its well documented and easy to edit.

Open up the file called "jquery.fancygestures.js". In its current state, the script is designed to allow you to create letters with mouse gestures. But that is not our purpose, so lets delete all the current gestures.

Now let's add a new custom gesture. Here is a example of one I created:

  1. gestures["Hello"] = "20";

Mouse Directions

The numbers you see may look like nonsense at first, but they stand for the direction of the mouse gesture. To understand better, please refer to this graphic:

The script reads the numbers as a sequence of mouse movement directions. Lets say I want to create a gesture for a line starting from the bottom going up. I would simply create a gesture like this:

  1. gestures["Hello"] = "6";

As you can see, "6" is the direction going up on the graphic. If you wanted a line going from top to bottom, use the number "2".

Now lets say you want to create a more complex gesture. Lets create a "L" shape with mouse gestures. Referring to the graphic, a "L" shape would have to either go down then right, or left then up. But in order to be sure that the user can create the shape starting at either point, we need to create two gestures:

  1. gestures["Hello"] = "46";
  2. gestures["Hello"] = "20";

As you can see on the graphic, "46" is going left then up thereby forming a "L". But if someone were to start from the top then right, the gesture would be invalid. So we have to create another gesture going down then right, hence "20". For the purposes of this tutorial, lets stick with the "L" shape.

(Optional) If you want to change the color of the stroke, or the line you create when you draw a gesture, change this to a HEX color of your choice:

  1. var color = "#3399CC";

Output the HTML

After you have created your gesture, edit the output to meet your needs. It can output HTML, so you can add the code for a register button, or even just a email address. Here is the format of a gesture:

  1. gestures["RETURNDATA"] = "MOUSESEQUENCE";

For this tutorial, lets say I want to protect my email address, and in order to do so, I must hide it and only allow those who have completed the gesture to see it. We can simply use HTML as we normally would for a email address.

  1. <a href="mailto:seanatdesignspasm [dot] net">seanatdesignspasm [dot] net</a>

So that is how I would normally write my email address in a HTML document. But we need to have the script output that, so lets move it over into the gestures javascript document.

  1. gestures["<a href=\"mailto:seanatdesignspasm [dot] net\">seanatdesignspasm [dot] net</a>"] = "20";
  2. gestures["<a href=\"mailto:seanatdesignspasm [dot] net\">seanatdesignspasm [dot] net</a>"] = "46";

Notice that I placed a "\" before and after the link. This is to ensure it renders the output correctly. The script will have trouble rendering HTML with quotes, so we have to neutralize it using "\". It will not work without this.

The HTML

Alright. Now that the script is ready, lets lay out the HTML. I created a container to house both the area where you can input a mouse gesture, as well as a place where the script can output the data.

  1. <div class="container">
  2.  
  3. <div id="input-box">
  4. <p>Draw Something</p>
  5. </div>
  6.  
  7. <div style="margin-left: 150px;">
  8. <h3>Email Address</h3>
  9. <p>Gotta keep those spambots out. For my email address, use your mouse to draw something in the box. <br /> <span class="note">(Just Click and Drag)</span></p>
  10. <div id="output-box">
  11. </div>
  12. </div>
  13.  
  14. </div>

The CSS

Now lets give it some style with CSS. This is just a simple style for it, but of course you can change it to meet your needs.

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. }
  5. body {
  6. font: Helvetica, sans-serif;
  7. width: 400px;
  8. margin-left: auto;
  9. margin-right: auto;
  10. background: #EFEFEF;
  11. }
  12.  
  13. a {
  14. color: #39F;
  15. text-decoration: none;
  16. }
  17.  
  18. p {
  19. line-height: 20px;
  20. color: #333333;
  21. margin-bottom: 3px;
  22. }
  23.  
  24. h2 {
  25. font-size: 26px;
  26. font-weight: 900;
  27. color: #3399FF;
  28. margin-bottom: 10px;
  29. }
  30.  
  31. .container {
  32. width: 390px;
  33. height: 150px;
  34. border: 1px solid #CCCCCC;
  35. padding: 10px;
  36. background: #F9F9F9;
  37. float: left;
  38. margin-right: 10px;
  39. position: relative;
  40. }
  41.  
  42. #input-box {
  43. width: 150px;
  44. height: 150px;
  45. background: #FFFFFF;
  46. border: 1px solid #3399FF;
  47. position: absolute;
  48. top: 10px;
  49. left: 10px;
  50. }
  51.  
  52. #input-box p {
  53. text-align: center;
  54. background: #3399CC;
  55. width: 100% !important;
  56. border-bottom: 1px solid ##3399FF;
  57. padding-top: 3px;
  58. padding-bottom: 3px;
  59. color: #FFFFFF;
  60. font-size: 12px !important;
  61. margin-left: 0 !important;
  62. margin-bottom: 0px !important;
  63. }
  64.  
  65. #output-box {
  66. width: 200px;
  67. background: #FFFFFF;
  68. border-bottom: 3px solid #3399FF;
  69. border-top: 3px solid #3399FF;
  70. height: 20px;
  71. float: left;
  72. padding: 6px;
  73. margin-left: 10px;
  74. overflow: hidden;
  75. }
  76.  
  77. #output-box a {
  78. color: #3399FF;
  79. font-size: 22px;
  80. clear: both;
  81. }
  82.  
  83. h3 {
  84. margin-left: 10px;
  85. float: left;
  86. width: 220px;
  87. margin-bottom: 3px;
  88. color: #444444;
  89. }
  90.  
  91. .container p {
  92. float: left;
  93. margin-left: 10px;
  94. width: 220px;
  95. font-size: 13px;
  96. margin-bottom: 29px;
  97. line-height: normal !important;
  98. }
  99. span.note {
  100. color: #A0A0A0;
  101. font-size: 10px;
  102. }

Add the Function

Now that everything is laid out and ready, lets activate Mouse Gestures. Place this script inside the head section.

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. $('#input-box').fancygestures(function (data) {
  4. });
  5. });
  6. </script>

The first part of this function activates fancy gestures on a div of your choice. Activating fancy gestures on a div means that you will be able to draw inside that div. We already created a div with the id "input-box", so lets activate it for that div.

Now we need to define a area to output the data for the correct gesture. I am choosing to script to output the data from the gesture into a div we created previously called "output-box".

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. $('#input-box').fancygestures(function (data) {
  4. document.getElementById('output-box').innerHTML += data;
  5. });
  6. });
  7. </script>

Finally, we need to make the box disappear once a gesture has been inputted. This prevents the user from doing multiple gestures. Lets just use the fadeOut effect from the jQuery library, since we have already included it in our document.

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. $('#input-box').fancygestures(function (data) {
  4. document.getElementById('output-box').innerHTML += data;
  5. $("#input-box").fadeOut("slow");
  6. });
  7. });
  8. </script>

Great! Now our document should be working. Open it in your browser and give it a shot.

Using it for Forms

Now, lets say you want to use this to protect your forms. What we can do is ensure that users must complete a gesture before the submit button appears. This is similar to using a captcha, except you do not have to submit in order for it to validate.

  1. gestures["<input type=\"button\" value=\"Submit\" class=\"submit\" />"] = "04";
  2. gestures["<input type=\"button\" value=\"Submit\" class=\"submit\" />"] = "40";

If you refer to the graphic, you will see that "0" and "4" are the left and right directions. Thereby creating a line.

This can be applied to almost anything. The possibilities are endless.

Why it works

How is this secure? When using it for emails, the script is outputting the email address only when the correct gesture is given. Spambots that crawl your web pages will not be able to find a email address and will not be able to complete the correct gesture. While this technique is still untested, it should in work in theory. In the end, it is just a fun and interactive way to protect your forms and other private information.

Internet Nerd, Design Freak, oh and Designmess Admin.

About Sean GengMember Since 08/03/2009

Web Designer, Web Developer

My name is Sean Geng. I'm a Freelance Web Designer, Graphic Designer, Motion Effects Artist, and Webmaster. I like to push the boundaries. I love creating unique, clean, usable design for the web and other digital sources.

CommentsAdd your comment

Brilliant idea! Sean, I really like your style and your work. Thanks for the post.

January 25, 2010 - 4:09pm

Thanks David! Glad you enjoyed it.

Internet Nerd, Design Freak, oh and Designmess Admin.

January 25, 2010 - 4:17pm

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <h3> <h4> <i> <b> <p> <a> <br /> <img> <em> <strong> <blockquote> <cite> <code> <ul> <ol> <li> <div class="info-block-left"> <div class="info-block-right"> <div class="quote-left"> <div class="quote-right"> <div class="notice"> <table> <thead> <tbody> <tr class="odd"> <tr class="even"> <tr> <td> <th>
  • You may post PHP code. You should include <?php ?> tags.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <actionscript-code>, <actionscript3-code>, <apache-code>, <asp-code>, <css-code>, <html-code>, <javascript-code>, <mysql-code>, <php-code>, <python-code>, <ruby-code>, <sql-code>, <xml-code>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Links to HTML content with 'rel="lightframe"' in the <a> tag will appear in a Lightbox when clicked on.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.
  • You may insert videos with [video:URL]

More information about formatting options

Other stories you might like

Sorry if its gonna be slow content wise for a week or so. Working on a free wordpress theme. Consider writing for us?