Index: image_captcha.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.admin.inc,v retrieving revision 1.8 diff -u -b -u -p -r1.8 image_captcha.admin.inc --- image_captcha.admin.inc 28 Apr 2008 10:03:00 -0000 1.8 +++ image_captcha.admin.inc 17 May 2008 13:44:06 -0000 @@ -42,6 +42,13 @@ function image_captcha_settings_form() { '#default_value' => (int) variable_get('image_captcha_code_length', 5), '#description' => t('The code length influences the size of the image. Note that larger values make the image generation more CPU intensive.'), ); + // Option fo case insensitive validation + $form['image_captcha_code_settings']['image_captcha_case_insensitive'] = array( + '#type' => 'checkbox', + '#title' => t('Case insensitive validation'), + '#description' => t('Enable this option to ignore uppercase/lowercase errors in the response. This can be usefull for adapting the challenge to your audience or for certain fonts where the differences between upper and lower case are too small.'), + '#default_value' => variable_get('image_captcha_case_insensitive', FALSE), + ); // font related stuff $form['image_captcha_font_settings'] = array( Index: image_captcha.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.module,v retrieving revision 1.14 diff -u -b -u -p -r1.14 image_captcha.module --- image_captcha.module 7 Apr 2008 21:35:18 -0000 1.14 +++ image_captcha.module 17 May 2008 13:44:06 -0000 @@ -102,7 +102,7 @@ function _image_captcha_utf8_split($str) /** * Implementation of hook_captcha */ -function image_captcha_captcha($op, $captcha_type='') { +function image_captcha_captcha($op, $captcha_type='', $response='') { switch ($op) { case 'list': // only offer image CAPTCHA if possible to generate an image CAPTCHA @@ -113,6 +113,7 @@ function image_captcha_captcha($op, $cap else { return array(); } + case 'generate': if ($captcha_type == 'Image') { // In offline mode, the image CAPTCHA does not work because the request @@ -129,11 +130,25 @@ function image_captcha_captcha($op, $cap for ($i = 0; $i < $code_length; $i++) { $code .= $allowed_chars[array_rand($allowed_chars)]; } + // store the answer in $_SESSION for the image generator function (which happens in another http request) $seed = mt_rand(); $_SESSION['image_captcha'][$seed] = $code; + // build the result to return $result = array(); + + // Handle the case insesitivity option and change the code to lower case + // before saving it as solution. + if (variable_get('image_captcha_case_insensitive', FALSE)) { + $code = strtolower($code); + $result['preprocess'] = TRUE; + $description = t('Enter the characters shown in the image without spaces.'); + } + else { + $description = t('Enter the characters shown in the image without spaces, also respect upper and lower case.'); + } + $result['solution'] = $code; $result['form']['captcha_image'] = array( '#type' => 'markup', @@ -143,13 +158,19 @@ function image_captcha_captcha($op, $cap $result['form']['captcha_response'] = array( '#type' => 'textfield', '#title' => t('What code is in the image?'), - '#description' => t('Copy the characters (respecting upper/lower case) from the image.'), + '#description' => $description, '#weight' => 0, '#required' => TRUE, '#size' => 15, ); return $result; } + + case 'preprocess': + // Preprocessing the response for case insesitive validation + if ($captcha_type == 'Image') { + return strtolower($response); + } break; } } Index: image_captcha.user.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.user.inc,v retrieving revision 1.10 diff -u -b -u -p -r1.10 image_captcha.user.inc --- image_captcha.user.inc 27 Mar 2008 00:07:47 -0000 1.10 +++ image_captcha.user.inc 17 May 2008 13:44:06 -0000 @@ -224,7 +224,7 @@ function _image_captcha_image_generator_ } } - /** +/** * Helper function for drawing text on the image * * @param $background_mode if the text is for the background of the double vision mode