Php 如何记录失败的MediaWiki登录尝试?

Php 如何记录失败的MediaWiki登录尝试?,php,mediawiki,Php,Mediawiki,我找不到登录尝试失败的MediaWiki挂钩事件。有人存在吗?如果没有,是否有人知道确定失败尝试的策略 如果有其他方法-我正在尝试记录失败的登录 编辑 下面是我的代码的相关部分,globals设置为wiki的名称(我还尝试了注释中提供的代码): 以上记录注册用户成功登录和失败登录。未注册用户名的登录尝试不会被记录。我将日志与Fail2Ban一起使用。使用挂钩。例如 use MediaWiki\Auth\AuthManager; use MediaWiki\Auth\AuthenticationR

我找不到登录尝试失败的MediaWiki挂钩事件。有人存在吗?如果没有,是否有人知道确定失败尝试的策略

如果有其他方法-我正在尝试记录失败的登录

编辑
下面是我的代码的相关部分,globals设置为wiki的名称(我还尝试了注释中提供的代码):

以上记录注册用户成功登录和失败登录。未注册用户名的登录尝试不会被记录。我将日志与Fail2Ban一起使用。

使用挂钩。例如

use MediaWiki\Auth\AuthManager;
use MediaWiki\Auth\AuthenticationResponse;

$wgHooks['AuthManagerLoginAuthenticateAudit'][] = function ( $response, $user, $username ) {
    if ( $response->status === AuthenticationResponse::FAIL ) {
        log( "Failed login for user $username" );
    }
};

要捕获上述钩子无法捕获的某些情况,可以创建日志提供程序:

use MediaWiki\Auth\AbstractPreAuthenticationProvider;
use MediaWiki\Auth\AuthenticationResponse;

class LoggingAuthenticationProvider extends AbstractPreAuthenticationProvider {
    public function postAuthentication( $user, AuthenticationResponse $response ) {
        if ( $response->status === AuthenticationResponse::FAIL && $user ) {
            log( 'Failed login for user ' . $user->getName() );
        }
    }
}

$wgAuthManagerAutoConfig['preauth'][LoggingAuthenticationProvider::class] = [
    'class' => LoggingAuthenticationProvider::class,
];

仅记录注册用户的失败尝试。对吗?我需要记录未注册用户名的尝试。用户,而不是用户,抱歉。不,它记录所有失败的尝试。我在文档中添加了更多细节,希望对您有所帮助。根据您的示例,我尝试了一些不同的设置。我仍然没有收到未注册用户的失败登录。嗯,你做错了什么。如果不看看你是如何尝试的,你很难比这更有用。
use MediaWiki\Auth\AbstractPreAuthenticationProvider;
use MediaWiki\Auth\AuthenticationResponse;

class LoggingAuthenticationProvider extends AbstractPreAuthenticationProvider {
    public function postAuthentication( $user, AuthenticationResponse $response ) {
        if ( $response->status === AuthenticationResponse::FAIL && $user ) {
            log( 'Failed login for user ' . $user->getName() );
        }
    }
}

$wgAuthManagerAutoConfig['preauth'][LoggingAuthenticationProvider::class] = [
    'class' => LoggingAuthenticationProvider::class,
];