13 protected function keyMatch( $answer, $info ) {
14 return (
int)$answer == (int)$info[
'answer'];
21 list( $sum, $answer ) = $this->
pickSum();
25 $resultArr[
'captcha'][
'id'] = $index;
26 $resultArr[
'captcha'][
'question'] = $html;
35 'mime' =>
'text/html',
44 list( $sum, $answer ) = $this->
pickSum();
47 $form =
'<table><tr><td>' . $this->
fetchMath( $sum ) .
'</td>';
48 $form .=
'<td>' . Html::input(
'wpCaptchaWord',
false,
false, [
49 'tabindex' => $tabIndex,
50 'autocomplete' =>
'off',
52 ] ) .
'</td></tr></table>';
53 $form .= Html::hidden(
'wpCaptchaId', $index );
54 return [
'html' => $form ];
62 $a = mt_rand( 0, 100 );
63 $b = mt_rand( 0, 10 );
64 $op = mt_rand( 0, 1 ) ?
'+' :
'-';
65 $sum =
"{$a} {$op} {$b} = ";
66 $ans = $op ==
'+' ? ( $a + $b ) : ( $a - $b );
67 return [ $sum, $ans ];
76 $math = MathRenderer::getRenderer( $sum, [],
'png' );
78 $html = $math->getHtmlOutput();
79 return preg_replace(
'/alt=".*?"/',
'', $html );
86 list( $sum, $answer ) = $this->
pickSum();
87 return [
'question' => $sum,
'answer' => $answer ];
96 $sum = $captchaData[
'question'];
107 array &$formDescriptor,
$action ) {
109 $req = AuthenticationRequest::getRequestByClass(
111 CaptchaAuthenticationRequest::class,
118 $formDescriptor[
'captchaInfo'][
'raw'] =
true;
119 $formDescriptor[
'captchaWord'][
'label-message'] =
null;
addCaptchaAPI(&$resultArr)
pickSum()
Pick a random sum.
getFormInformation( $tabIndex=1)
keyMatch( $answer, $info)
Validate a captcha response.
getCaptchaInfo( $captchaData, $id)
onAuthChangeFormFields(array $requests, array $fieldInfo, array &$formDescriptor, $action)
fetchMath( $sum)
Fetch the math.
Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs.
string $action
Used to select the right message.
storeCaptcha( $info)
Generate a captcha session ID and save the info in PHP's session storage.