novy213/yii2-otp
Composer 安装命令:
composer require novy213/yii2-otp
包简介
YII2 extension for generating one time passwords according to RFC 4226/6238 (HOTP/TOTP Algorithm) and authentication widget
README 文档
README
YII2 extension for generating one time passwords according to RFC 4226 (HOTP Algorithm) and the RFC 6238 (TOTP Algorithm)
Installation
The preferred way to install this extension is through composer.
Either run
composer require novy213/yii2-otp:~2.0.0
or add
"novy213/yii2-otp" : "~2.0.0"
to the require section of your application's composer.json file.
Usage
After extension is installed you need to setup auth client collection application component:
Configure
<?php use novy213\otp\Otp; ... 'components' => [ 'otp' => [ 'class' => Otp::className(), // 'totp' only now 'algorithm' => novy213\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' ], ... ]
Add behavior Add any model column for storing secure code. //My case: the use of two-factor authentication
<?php use novy213\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 ], ... ]
Widget use Widget for generate init QR-code. Read more about QrParams in the qrcode-library.
use novy213\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, ] ]); ?>
Further Information
Credits
License
The LGPLv3 License. Please see License File for more information.
novy213/yii2-otp 适用场景与选型建议
novy213/yii2-otp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 01 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Authentication」 「two-factor」 「otp」 「hotp」 「totp」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 novy213/yii2-otp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 novy213/yii2-otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 novy213/yii2-otp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Filament Two Factor Authentication: Google 2FA + Passkey Authentication
Automatically logs-in users if they are already authenticated by a remote source. (e.g. environment variable REMOTE_USER)
GraphQL authentication for your headless Craft CMS applications.
Novactive eZ 2FA Bundle is an Ibexa bundle that provides two-factor authentication for your Ibexa project
Two-factor Authentication for WordPress
Laravel middleware to restrict a site or specific routes using HTTP basic authentication
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2024-01-15