美文网首页
php实现authenticator功能

php实现authenticator功能

作者: 江江简书 | 来源:发表于2021-12-15 17:41 被阅读0次

最近在实现一个MFC【多因子验证】来实现二次验证,分享以下整个过程

下载手机app

  • Authenticator(可以微软/谷歌)

php代码实现输出

//参考文档

https://github.com/Spomky-Labs/otphp/blob/HEAD/doc/index.md

<?php
namespace app\controller\user;

use OTPHP\TOTP;
use app\BaseController;

class Authenticator extends BaseController
{
   public function generateQrcode1()
    {
        $otp = TOTP::create();
        $scret = $otp->getSecret();
        echo "The OTP secret is: {$otp->getSecret()}\n";

        //生成6位数码
        echo "The current OTP is: {$otp->now()}\n";
        echo '<pre/>';
         //生成可扫描二维码
        $otp->setLabel('OA令牌验证功能');
        $grCodeUri = $otp->getQrCodeUri(
            'https://api.qrserver.com/v1/create-qr-code/?data=[DATA]&size=200x200&ecc=M',
            '[DATA]'
        );
        echo "<img src='{$grCodeUri}'>";
        echo '<pre/>';
        //解密
        $otp = TOTP::create($scret); // create TOTP object from the secret.

        var_dump($otp->verify($otp->now())); // Returns true if the input is verified, otherwise false.
    }

}
* 注意如果要固定scret则要存起来,否则每次刷新后都是一个全新的值

相关文章

网友评论

      本文标题:php实现authenticator功能

      本文链接:https://www.haomeiwen.com/subject/yfepfrtx.html