Math CAPTCHA doesn't allow for enough digits

fractile81 - June 26, 2009 - 14:57
Project:CAPTCHA Pack
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:minor
Assigned:Unassigned
Status:closed
Description

I've run into a problem where a Match CAPTCHA expects a specific response but does not allow for enough characters in the input field. For example:

10 - ? = 0

I go to enter 10 for the ?, and am only allowed 1 character in the input field.

Digging into the problem, it's actually a really easy fix. Open up match_captcha.challenge.inc, and on line 81 (create a newline before the return), add:

<?php
$form_item
['form']['captcha_response']['#maxlength'] = strlen($form_item['solution']);
?>

Without this fix, you will only be allowed to enter as many characters long as the result (right side of the =, see line 63 in the same file). This change will allow you to properly enter up to as many characters as the solution requires.

#1

soxofaan - June 26, 2009 - 19:51
Status:active» fixed

Good catch!
thanks

fixed by http://drupal.org/cvs?commit=230290

note: I solved it slightly different:

<?php
'#maxlength' => max(strlen("$result"), strlen("$x"), strlen("$y")),
?>

#2

soxofaan - June 29, 2009 - 19:36
Priority:normal» minor
Status:fixed» needs work

still some refining needed.

Just observed minor very low frequency problem with admin mode:
* captcha on create page node form and admin mode enabled
* go to create page node form (with solution = 10)
* preview
* form gets rebuilt with likely a solution different from 10
* drupal complains that the default value is larger than the maxlength permits (or something like that)

fix: maxlength should be the maximum length of all possible values in the enabled range, not the maximum of $x, $y and $result.

#3

soxofaan - July 24, 2009 - 16:17
Status:needs work» fixed

#2 fixed by http://drupal.org/cvs?commit=242336

#4

soxofaan - July 24, 2009 - 16:25

#5

System Message - August 7, 2009 - 16:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.