sam002/yii2-otp

根据RFC 4226/6238 (HOTP/TOTP算法)生成一次性密码的YII2扩展和身份验证小部件

安装次数: 891

依赖关系: 0

建议者: 0

安全: 0

星标: 14

关注者: 2

分支: 6

开放问题: 1

类型:yii2-extension

2.0.0 2018-01-14 18:00 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:26:13 UTC


README

Code Climate SensioLabsInsight

Latest Version Software License

Build Status

根据RFC 4226 (HOTP算法)和RFC 6238 (TOTP算法)生成一次性密码的YII2扩展

安装

安装此扩展的首选方式是通过composer

运行以下命令之一

composer require sam002/yii2-otp:~2.0.0

"sam002/yii2-otp" : "~2.0.0"

将以下内容添加到您应用程序的composer.json文件的require部分。

用法

安装扩展后,您需要设置auth client collection应用程序组件

配置

<?php
use sam002\otp\Otp;

...

'components' => [
    'otp' => [
        'class' => Otp::className(),
        // 'totp' only now
        'algorithm' => sam002\otp\Otp::ALGORITHM_TOTP,
        
        // length of code
        'digits' => 6,
        
        //  Algorithm for hashing
        'digest' => 'sha1',
        
        // Label of application
        'label' => 'yii2-otp',
        
        // Uri to image (application icon)
        'imgLabelUrl' => Yii::to('/icon.png'),
        
        // Betwen 8 and 1024
        'secretLength' => 64,
        // Time interval in seconds, must be at least 1
        'interval'
    ],
...
]

添加行为 添加任何用于存储安全代码的模型列。//我的案例:使用双因素认证

<?php
use sam002\otp\behaviors\OtpBehavior;

...

'behavior' => [
    'otp' => [
        'class' => OtpBehavior::className(),
        // Component name
        'component' => 'otp',
        
        // column|property name for get and set secure phrase
        //'secretAttribute' => 'secret'
        // column|property name for get code and confirm secret
        //'codeAttribute' => 'secret'
        
        //Window in time for check authorithation (current +/- window*interval) 
        //'window' => 0
    ],
...
]

小部件使用 使用小部件生成初始二维码。有关QrParams的更多信息,请参阅qrcode-library

use sam002\otp\widgets\OtpInit;

<?php echo $form->field($model, 'secret')->widget(
                    OtpInit::className() ,[
                        'component'=>'otp',
                        
                        // link text
                        'link' => 'ADD OTP BY LINK',
                        
                        'QrParams' => [
                            // pixels width
                            'size' => 300,
                            
                            // margin around QR-code
                            'margin' => 10,
                            
                            // Path to logo on image
                            'logo' => '/icon.png',
                            
                            // Width logo on image
                            'logoWidth' => 50,
                            
                            // RGB color
                            'foregroundColor' => [0,0,0],
                            
                            // RGB color
                            'backgroundColor' => [255,255,255],
                            
                            // Qulity of QR: LOW, MEDIUM, HIGHT, QUARTILE
                            'level' => ErrorCorrectionLevelInterface::HIGH,
                            
                            // Image format: PNG, JPG, SVG, EPS
                            'type' => PngWriter::class,
                            
                            // Locale
                            'encoding' => 'UTF-8',
                            
                            // Text on image under QR code
                            'label' => 'QR code',
                            
                            // by default image create and save at Yii::$app->runtimePath . '/temporaryQR/'
                            'outfile' => '/tmp/'.uniqid(),
                            
                            // save or delete after generate
                            'save' => false,
                        ]
                ]); ?>

更多信息

致谢

许可协议

本软件使用LGPLv3许可协议。有关更多信息,请参阅许可文件