Changes to _textimage_captcha_code() in captcha.inc, the function that builds the string of characters that will be displayed in the captcha image.

1. When using the built-in fonts, the character "m" is often displayed so that it can't be distinguished from an "n", causing the user to enter the wrong string. So remove the character "m" from the list of possible characters.

2. Although the string should be random, the string from the current code always outputs vowels and consonants in the same order. Change it to be truly random.

3. Simplify the code.

So change from:

function _textimage_captcha_code() {
  $consts='bcdgjxvmnprst';
  $vowels='aeiou';

  for ($x=0; $x < 6; $x++) {
    mt_srand ((double) microtime() * 1000000);
    $const[$x] = drupal_substr($consts,mt_rand(0,drupal_strlen($consts)-1),1);
    $vow[$x] = drupal_substr($vowels,mt_rand(0,drupal_strlen($vowels)-1),1);
  }

  $string = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
  $string = drupal_substr($string,0,rand(4,6));

  //everytime we create a new code, we write it to session
  $_SESSION['captcha'] = drupal_strtolower($string);

  if(variable_get('textimage_captcha_use_only_upper',0)) {
    $string = drupal_strtoupper($string);
  }

  return $string;
}

To:

function _textimage_captcha_code() {
  // don't use "m", as it looks like "n" when displayed
  $letters='abcdegijnoprstuvx';

  $captchaLength = rand(4,6);
  $captchaString = '';

  for ($x=0; $x < $captchaLength; $x++) {
    mt_srand ((double) microtime() * 1000000);
    $captchaString = $captchaString . drupal_substr($letters,mt_rand(0,drupal_strlen($letters)-1),1);
  }

  //everytime we create a new code, we write it to session
  $_SESSION['captcha'] = drupal_strtolower($captchaString);

  if(variable_get('textimage_captcha_use_only_upper',0)) {
    $captchaString = drupal_strtoupper($captchaString);
  }

  return $captchaString;
}

Comments

deciphered’s picture

Status: Active » Closed (fixed)

Captcha no longer supported in Textimage.