agp/twofactor

双因素认证包

1.0.4 2023-10-18 15:25 UTC

This package is not auto-updated.

Last update: 2024-09-23 16:52:09 UTC


README

双因素包

双因素认证包。

菜单

项目Git

AGP/package-twofactor

讨论论坛

AGP论坛

要求

  • PHP 7.2+

安装

composer require agp/twofactor

第二步是检查在该文件中使用的变量是否已在.env中设置。

API_AGPADMIN=value

使用

如何生成和使用双因素认证

创建

为您的用户生成一个密钥并保存其ID。

use Agp\TwoFactor\GoogleAuthentication;
    
$googleAuthenticator = new GoogleAuthentication();

return $googleAuthenticator->create($adm_pessoa_id);
{
    "data": {
        "adm_pessoa_id": 2,
        "verificado": 0,
        "secret_key": "LIZGIMFYTHSDXKBG7TTR4SMLEWTIBNMYNZSO4B..."
    }
}

如果用户已有密钥且验证通过,则字段secret_key的值为"null"。

显示二维码

<img src="{{ (new \chillerlan\QRCode\QRCode)->render($googleAuthenticator->secret_key) }}" alt="">

作为要求,我们包中已包含chillerlan QrCode,但您也可以使用您偏好的二维码生成器。

验证

$secret = $request->input('secret');

$valid = (new GoogleAuthentication())->verify($adm_pessoa_id, $secret);

如果verify方法没有抛出任何异常,则$valid的值为"true"。

查询

use Agp\TwoFactor\GoogleAuthentication;
    
$googleAuthenticator = new GoogleAuthentication();
    
return $googleAuthenticator->get($adm_pessoa_id);

禁用

要禁用认证,需要发送一个代码。

$secret = $request->input('secret');

(new GoogleAuthentication())->destroy($adm_pessoa_id, $secret);

版权

AGP @ 2020