You are here

function _math_captcha_multiplication_challenge in CAPTCHA Pack 8

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

Function for multiplication challenges.

File

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

Code

function _math_captcha_multiplication_challenge() {
  $config = Drupal::config('math_captcha.settings');
  $argmax = intval($config
    ->get('math_captcha_multiplication_argmax'));
  $x = mt_rand(1, $argmax);
  $y = mt_rand(1, $argmax);
  if ($config
    ->get('math_captcha_multiplication_allow_negative')) {
    $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($config
    ->get('math_captcha_multiplication_allow_negative'));
  return _math_captcha_build_captcha($x, $y, '*', $solution, $maxlength);
}