x1ankun/yii2-google-authenticator

This package is abandoned and no longer maintained. No replacement package was suggested.

Yii 2 extension wrapper to google authenticator

v1.0.0 2018-02-21 05:56 UTC

This package is auto-updated.

Last update: 2018-11-09 08:13:56 UTC


README

GitHub tag GitHub tag GitHub tag

此PHP组件可用于与Google身份验证器移动应用程序进行交互以进行双因素身份验证。 该组件可以生成秘密、生成代码、验证代码并呈现用于扫描秘密的QR码。 它根据RFC6238实现TOTP

For a secure installation you have to make sure that used codes cannot be reused (replay-attack). You also need to limit the number of verifications, to fight against brute-force attacks. For example you could limit the amount of verifications to 10 tries within 10 minutes for one IP address (or IPv6 block). It depends on your environment.

Installation

composer require gengxiankun/yii2-google-authenticator v1.0.0

Configuration

//google authenticator应用组件(config/main.php or config/main-local.php)
'components' => [
    'authenticator' => [
        'class' => 'gengxiankun\Authenticator\GoogleAuthenticator'
    ]
]

Usage example

$authenticator = \Yii::$app->authenticator;

//生成Google Authenticator Secret
$secret = $authenticator->secret;

//Google Charts URL for the QR-Code
$authenticator->secret = $secret;
$authenticator->name = 'EXAMPLE';
$qRCodeGoogleUrl = $authenticator ->qRCodeGoogleUrl;

//验证Code码
$code = $authenticator->code;
$authenticator->verifyCode($code); //return bool