promocat/yii2-twofa 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

promocat/yii2-twofa

Composer 安装命令:

composer require promocat/yii2-twofa

包简介

Provides TOTP and QR codes for use with an authenticator like the one from Google or Authy

README 文档

README

Provides TOTP and QR codes for use with an authenticator like the one from Google or Authy

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist promocat/yii2-twofa "*"

or add

"promocat/yii2-twofa": "*"

to the require section of your composer.json file.

Setup

Update the user component in your config file to use the class

promocat\twofa\User::class

It should sorta look like this

'components' => [
    'user' => [
        'class' => promocat\twofa\User::class,
        'identityClass' => 'common\models\User',
        'enableAutoLogin' => true,
        'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
    ]
]

Also add the "twoFa" component:

'twoFa' => ['class' => promocat\twofa\TwoFa::class]

Next, add the TwoFaBehavior to your User model

public function behaviors() {
    return [
        'two_fa' => ['class' => TwoFaBehavior::class]
    ];
}

Usage

Congratulations, you can now, for example, call

Yii::$app->twofa->generateSecret()

or

Yii::$app->twofa->checkCode($secret, $code);

Use

promocat\models\TwoFaForm

for the 2FA activation and verification forms. Or at least let is be an example.

QR Code Widget

<?= TwoFaQr::widget([
    'accountName' => $model->user->username,
    'secret' => $model->secret,
    'issuer' => Yii::$app->params['twoFaIssuer'],
    'size' => 300
]); ?>

How to functionally implement:

See "example.php" to get started.

统计信息

  • 总下载量: 25.27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-05-16