You are here

function _math_captcha_multiplication_challenge in CAPTCHA Pack 7

Same name and namespace in other branches
  1. 8 math_captcha/math_captcha.challenge.inc \_math_captcha_multiplication_challenge()
  2. 5 math_captcha/math_captcha.module \_math_captcha_multiplication_challenge()
  3. 6 math_captcha/math_captcha.challenge.inc \_math_captcha_multiplication_challenge()

Function for multiplication challenges

File

math_captcha/math_captcha.challenge.inc, line 47
Provides challenge functions for MATH CAPTCHA administration.

Code

function _math_captcha_multiplication_challenge() {
  $argmax = intval(variable_get('math_captcha_multiplication_argmax', 5));
  $x = mt_rand(1, $argmax);
  $y = mt_rand(1, $argmax);
  if (variable_get('math_captcha_multiplication_allow_negative', FALSE)) {
    $x = $x * (mt_rand(0, 1) * 2 - 1);
    $y = $y * (mt_rand(0, 1) * 2 - 1);
  }
  $solution = $x * $y;
  $maxlength = strlen(strval($argmax * $argmax)) + intval(variable_get('math_captcha_multiplication_allow_negative', FALSE));
  return _math_captcha_build_captcha($x, $y, '*', $solution, $maxlength);
}