function _math_captcha_addition_challenge in CAPTCHA Pack 8
Same name and namespace in other branches
- 5 math_captcha/math_captcha.module \_math_captcha_addition_challenge()
- 6 math_captcha/math_captcha.challenge.inc \_math_captcha_addition_challenge()
- 7 math_captcha/math_captcha.challenge.inc \_math_captcha_addition_challenge()
Function for addition challenges.
File
- math_captcha/
math_captcha.challenge.inc, line 11 - Provides challenge functions for MATH CAPTCHA administration.
Code
function _math_captcha_addition_challenge() {
$config = Drupal::config('math_captcha.settings');
$argmax = intval($config
->get('math_captcha_addition_argmax'));
if ($config
->get('math_captcha_addition_allow_negative')) {
$x = mt_rand(-$argmax, $argmax);
$y = mt_rand(-$argmax, $argmax);
}
else {
$x = mt_rand(0, $argmax);
$y = mt_rand(0, $argmax);
}
$solution = $x + $y;
$maxlength = strlen(strval($argmax + $argmax)) + intval($config
->get('math_captcha_addition_allow_negative'));
return _math_captcha_build_captcha($x, $y, '+', $solution, $maxlength);
}