Commit 64aa7be3 authored by soxofaan's avatar soxofaan
Browse files

#644046: image CAPTCHA ignores spaces in the user's response (lower barrier...

#644046: image CAPTCHA ignores spaces in the user's response (lower barrier for humans, but not easier for bots)
parent d4b482c0
// $Id$
Readme file for the CAPTCHA module for Drupal
---------------------------------------------
---------------------------------------------
captcha.module is the basic CAPTCHA module, offering general CAPTCHA
administration and a simple math challenge.
......@@ -11,7 +11,7 @@ Submodule image_captcha.module offers an image based challenge.
Installation:
Installation is like with all normal drupal modules:
extract the files from the tar ball to a directory like sites/all/modules.
Dependecies:
The basic CAPTCHA module has no dependencies, so nothing special is required.
......
......@@ -393,6 +393,26 @@ function captcha_validate_case_insensitive_equality($solution, $response) {
return strtolower($solution) === strtolower($response);
}
/**
* CAPTCHA validation function to tests equality while ignoring spaces.
* @param $solution the solution of the test.
* @param $response the response to the test.
* @return TRUE when equal (ignoring spaces), FALSE otherwise.
*/
function captcha_validate_ignore_spaces($solution, $response) {
return preg_replace('/\s/', '', $solution) == preg_replace('/\s/', '', $response);
}
/**
* CAPTCHA validation function to tests case insensitive equality while ignoring spaces.
* @param $solution the solution of the test.
* @param $response the response to the test.
* @return TRUE when equal (ignoring spaces), FALSE otherwise.
*/
function captcha_validate_case_insensitive_ignore_spaces($solution, $response) {
return preg_replace('/\s/', '', strtolower($solution)) == preg_replace('/\s/', '', strtolower($response));
}
/**
* CAPTCHA validation handler.
*
......
......@@ -12,6 +12,7 @@
// TODO: test about placement (comment form, node forms, log in form, etc)
// TODO: test if captcha_cron does it work right
// TODO: test custom CAPTCHA validation stuff
// TODO: test space ignoring validation of image CAPTCHA
class CapchaTestCase extends DrupalWebTestCase {
......
......@@ -159,15 +159,6 @@ function image_captcha_captcha($op, $captcha_type='', $captcha_sid=NULL) {
// 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 (CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE == variable_get('captcha_default_validation', CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE)) {
$description = t('Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.');
}
else {
$description = t('Enter the characters (without spaces) shown in the image.');
}
$result['solution'] = $code;
// Generate image source URL (add timestamp to avoid problems with
// client side caching: subsequent images of the same CAPTCHA session
......@@ -181,11 +172,23 @@ function image_captcha_captcha($op, $captcha_type='', $captcha_sid=NULL) {
$result['form']['captcha_response'] = array(
'#type' => 'textfield',
'#title' => t('What code is in the image?'),
'#description' => $description,
'#description' => t('Enter the characters shown in the image.'),
'#weight' => 0,
'#required' => TRUE,
'#size' => 15,
);
// Handle the case insensitive validation option combined with ignoring spaces.
switch (variable_get('captcha_default_validation', CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE)) {
case CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE:
$result['captcha_validate'] = 'captcha_validate_ignore_spaces';
break;
case CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE:
$result['captcha_validate'] = 'captcha_validate_case_insensitive_ignore_spaces';
break;
}
return $result;
}
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment