You are here

function _math_captcha_subtraction_challenge in CAPTCHA Pack 8

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

Function for subtraction challenges.

File

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

Code

function _math_captcha_subtraction_challenge() {
  $config = Drupal::config('math_captcha.settings');
  $argmax = intval($config
    ->get('math_captcha_subtraction_argmax'));
  if ($config
    ->get('math_captcha_subtraction_allow_negative')) {
    $x = mt_rand(-$argmax, $argmax);
    $y = mt_rand(-$argmax, $argmax);
  }
  else {
    $y = mt_rand(0, $argmax);
    $x = mt_rand($y, $argmax);
  }
  $solution = $x - $y;
  $maxlength = strlen(strval($argmax + $argmax)) + intval($config
    ->get('math_captcha_subtraction_allow_negative'));
  return _math_captcha_build_captcha($x, $y, '-', $solution, $maxlength);
}