Dr. Dobb's Journal - January 2008 - (Page 34) d01summ_p2ds 11/9/07 11:00 AM Page 34 Core Technology IMPLEMENTING AUDIO CAPTCHA continued from page 31 swank soiree. An audio CAPTCHA, on the other hand, is an attractive alternative to its visual counterpart. Some people may be sufficiently turned off at the thought of navigating yet another visual CAPTCHA that they turn away from your site. Providing an alternative that may be easier for some people to navigate may prove an incentive for more people to unlock the virtual door to your site feedback. Another reason for considering alternatives to visual CAPTCHA mechanisms involves a government regulation called “Section 508,” officially known as “The Federal Electronic and Information Technology Accessibility and Compliance Act.” Section 508 (www.section508.gov) says that when Federal agencies develop or use electronic information, they are required to make that information available to everyone equally. In the case of CAPTCHA, this means that people who are unable to read a CAPTCHA should have access to an alternate entry mechanism. At least, that’s my translation of the regulation’s government-ese. To date, Section 508 requirements apply only to sites with financial ties to the federal government. However, it makes good sense, from a business as well as a human standpoint, to provide accessibility alternatives for people with different physical challenges. Think about implementing these alternatives on your personal website as well as the business sites you develop. Sound Advice People who are sight challenged would naturally be an audience for an audio CAPTCHA. With this in mind, any audio CAPTCHA implementation should be constructed such that it’s easy to use by people who use a screen reader. You can test how well your audio CAPTCHA works for someone who is using a screen reader by using the “Microsoft Narrator” Figure 2: The Simple UI. that comes with Windows. You turn this feature on in Windows XP by selecting Start|All Programs|Accessories|Accessibility|Narrator. Any instructions that go with your CAPTCHA should be concise. Someone using a screen reader isn’t going to want to have it reread some overly verbose instructions. The implementation I present here can be used without employing the mouse at all. This feature is especially handy for someone using screen readers. I ask users to type a particular key to start the audio. Then once the audio has started, I move the focus to the proper text box and submit for validation upon getting the Enter key. When implementing an audio CAPTCHA, it is still necessary to disguise the challenge in some way from robots. However, there are ways to deceive these machines that are much less intrusive and easier for a human to deal with than using pictures of distorted letters. Some audio CAPTCHAs currently in use attempt to foil audio deciphering robots by obscuring the audio. To me, this defeats some of the purpose. Like the aforementioned swirling syllables, when you obscure audio, you make it harder for humans to understand as well as any mechanical facsimiles. Instead of adding background noises or any similar muddiness to the sound, try adding some simple aural logic that a machine would find difficult to parse. In my implementation, I ask for four numbers. The challenge starts with a simple instruction “Please enter these four numbers…,” then speaks the four random numbers (Figure 2). Available online (see “Resource Center, page 5) is a series of MP3 audio files for the numbers 0–9. A nice addition, that should help to obscure the challenge from robots, would be to randomly include a phrase between two of the numbers like, “not 7, but instead a.” So, for example, instead of hearing, “Please enter these four numbers—4,3,6,2,” the user hears “Please enter these four numbers— 4,3,6, not 7 but instead 2” . Naturally, in this example you would have to add logic to ensure that the fourth number asked for was not a 7. Other methods might include simply adding phrases like “and a,” “then press Enter,” and so on. My goals were to keep things simple by using only a small amount of code with no outside dependencies The idea here is to add just enough audio to fool the robots without confusing or frustrating users. Roll Tape When I created my audio CAPTCHA, my goals were to keep things simple by using only a small amount of code with no outside dependencies. I also wanted to keep the instructions and user interaction as simple as possible. A solution using PHP seemed best for this, with some JavaScript to handle browser independence and keyboard input. The main file, index.htm (Listing One), starts by setting a PHP session with a call to session_start(). Sessions are used in PHP as a persistence mechanism, letting data be passed from one page to another. (For more information on PHP sessions, see us2.php .net/session). After setting the session, the PHP script loads an array with four random numbers, from 0 to 9. These numbers serve as the basis for the randomly generated audio and are used to verify the subsequent user entry. The four digits are then concatenated together and stored in the $_SESSION global array variable. Here I make use of PHP’s associative array feature, naming this array index "captchaAnswer". When the page is loaded, a JavaScript Init() function is called. This simply makes sure that the text box is free of any previous entry. The next two functions determine the user’s browser and OS. If the user is running Internet Explorer under Windows, I want to use an embedded Windows Media Player to play the sound files. A JavaScript function KeyCheck() is called when the browser gets an onkeyup message. I use the key up rather than the key down because the key down can be generated more than once if the user holds a key down for a certain length of time. 34 Dr. Dobb’s Journal l www.ddj.com l January 2008 http://www.section508.gov http://us2.php.net/session http://us2.php.net/session http://www.ddj.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.