11 $captcha = ConfirmEditHooks::getInstance();
12 $user = User::newFromName( $options[
'username'] );
16 case AuthManager::ACTION_CREATE:
17 $needed = $captcha->needCreateAccountCaptcha( $user ?:
new User() );
19 $captcha->setAction(
'accountcreate' );
20 LoggerFactory::getInstance(
'authevents' )
21 ->info(
'Captcha shown on account creation', [
22 'event' =>
'captcha.display',
23 'eventType' =>
'accountcreation',
27 case AuthManager::ACTION_LOGIN:
39 $session = $this->manager->getRequest()->getSession();
40 $sessionFlag = $session->get(
'ConfirmEdit:loginCaptchaPerUserTriggered' );
41 $suggestedUsername = $session->suggestLoginUsername();
43 $captcha->isBadLoginTriggered()
45 || $suggestedUsername && $captcha->isBadLoginPerUserTriggered( $suggestedUsername )
48 $captcha->setAction(
'badlogin' );
49 LoggerFactory::getInstance(
'authevents' )
50 ->info(
'Captcha shown on account creation', [
51 'event' =>
'captcha.display',
52 'eventType' =>
'accountcreation',
60 return [ $captcha->createAuthenticationRequest() ];
67 $captcha = ConfirmEditHooks::getInstance();
68 $username = AuthenticationRequest::getUsernameFromRequests( $reqs );
70 $isBadLoginPerUserTriggered = $username ?
71 $captcha->isBadLoginPerUserTriggered( $username ) :
false;
73 if ( $captcha->isBadLoginTriggered() || $isBadLoginPerUserTriggered ) {
74 $captcha->setAction(
'badlogin' );
75 $captcha->setTrigger(
"post-badlogin login '$username'" );
77 LoggerFactory::getInstance(
'authevents' )->info(
'Captcha submitted on login', [
78 'event' =>
'captcha.submit',
79 'eventType' =>
'login',
84 if ( $isBadLoginPerUserTriggered || $isBadLoginPerUserTriggered ===
null ) {
85 $session = $this->manager->getRequest()->getSession();
86 $session->set(
'ConfirmEdit:loginCaptchaPerUserTriggered',
true );
91 return $success ? Status::newGood() : $this->
makeError(
'wrongpassword', $captcha );
95 $captcha = ConfirmEditHooks::getInstance();
97 if ( $captcha->needCreateAccountCaptcha( $creator ) ) {
98 $username = $user->getName();
99 $captcha->setAction(
'accountcreate' );
100 $captcha->setTrigger(
"new account '$username'" );
102 LoggerFactory::getInstance(
'authevents' )->info(
'Captcha submitted on account creation', [
103 'event' =>
'captcha.submit',
104 'eventType' =>
'accountcreation',
108 return $this->
makeError(
'captcha-createaccount-fail', $captcha );
111 return Status::newGood();
115 $captcha = ConfirmEditHooks::getInstance();
117 case AuthenticationResponse::PASS:
118 case AuthenticationResponse::RESTART:
119 $session = $this->manager->getRequest()->getSession();
120 $session->remove(
'ConfirmEdit:loginCaptchaPerUserTriggered' );
121 $captcha->resetBadLoginCounter( $user ? $user->getName() : null );
123 case AuthenticationResponse::FAIL:
124 $captcha->increaseBadLoginCounter( $user ? $user->getName() : null );
139 $req = AuthenticationRequest::getRequestByClass( $reqs,
140 CaptchaAuthenticationRequest::class,
true );
155 return Status::newFatal(
wfMessage(
'captcha-error', $error ) );
157 return Status::newFatal( $message );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
testForAccountCreation( $user, $creator, array $reqs)
Determine whether an account creation may begin.
getAuthenticationRequests( $action, array $options)
Return the applicable list of AuthenticationRequests.
makeError( $message, SimpleCaptcha $captcha)
verifyCaptcha(SimpleCaptcha $captcha, array $reqs, User $user)
Verify submitted captcha.
postAuthentication( $user, AuthenticationResponse $response)
Post-login callback.
testForAuthentication(array $reqs)
Determine whether an authentication may begin.
Demo CAPTCHA (not for production usage) and base class for real CAPTCHAs.
getError()
Return the error from the last passCaptcha* call.
passCaptchaLimited( $index, $word, User $user)
Checks, if the user reached the amount of false CAPTCHAs and give him some vacation or run self::pass...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...