enygma/gauth
Composer 安装命令:
composer require enygma/gauth
包简介
PHP library to generate codes compatible with the Google Authenticator clients
README 文档
README
The GAuth library is designed to generate and validate codes compatible with the
Google Authenticator tools.
Installation via Composer:
Include in your composer.json file:
{
"require": {
"enygma/gauth": "dev-master"
}
}
Getting Started
To get started using the Google Authenticator with your application, you'll need to make an
initialization key (using generateCode) and save that to your app's settings. This is the
code you'll share with your users when they're trying to set up their client for your system.
Then, when they log in you have them enter in the latest code listed for your application for thier account.
NOTE: This tool offers a "window of opportunity" for the codes of 2 seconds forward and
backward of the current timestamp, just in case things are a bit off. You can change this with
the setRange method:
<?php $g = new \GAuth\Auth(); // set it to 3 seconds $g->setRange(3); ?>
To generate a new code:
<?php require_once 'vendor/autoload.php'; // Useful for creating a new Initialization key if needed $g = new \GAuth\Auth(); $code = $g->generateCode(); var_dump($code); ?>
To validate a code
<?php $code = 'code-inputted-from-user'; $g = new \GAuth\Auth('your-initialization-code'); $verify = $g->validateCode($code); if ($verify == true) { echo 'User code verified!'; } else { echo 'User code invalid!'; } ?>
To get the QR code for the application
You can also use the tool to get the URL for a QR code users can scan to add your application to their Authenticator client. The call to generateQrImage returns the actual image data for you to use as you wish, either to embed in an img tag or save to a file:
<?php $holder = 'foo@bar.com'; $name = 'my-app-name'; $g = new \GAuth\Auth('your-initialization-code'); $qrCodeImageData = $g->generateQrImage($holder, $name, 200); // To use in an image tag: echo '<img src="data:image/png;base64,'.base64_encode($qrCodeImageData).'"/><br/><hr/>'; // Or just save to a file file_put_contents('/path/to/qr-file.png', $qrCodeImageData); ?>
The library uses internal QR code generation, not the Google Charts API many similar libraries use.
More info:
enygma/gauth 适用场景与选型建议
enygma/gauth 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 131.43k 次下载、GitHub Stars 达 75, 最近一次更新时间为 2013 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google」 「twofactor」 「authenticator」 「codes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 enygma/gauth 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 enygma/gauth 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 enygma/gauth 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library to interface with the Yubikey REST API
Rinvex Authy is a simple wrapper for Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
Rinvex Authy is a simple wrapper for Authy TOTP, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
Basic CAS (SSO) authenticator for Symfony 5.4, 6.0, 7.0 and 8.0
Allows your users to activate 2FA authentication.
Time-based One-time Password implementation for Nette framework
统计信息
- 总下载量: 131.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 75
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-07