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 |
Jump to:
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
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
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
#2 fixed by http://drupal.org/cvs?commit=242336
#4
d5 also: http://drupal.org/cvs?commit=242344
#5
Automatically closed -- issue fixed for 2 weeks with no activity.