PHP code example of lizhijun / php-totp

1. Go to this page and download the library: Download lizhijun/php-totp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lizhijun / php-totp example snippets


use Lizhijun\TOTP\TOTPAuth;

public function generateTOTP(){
    $auth = new TOTPAuth();
    $secret = $auth->createSecret();
    $qrcodeStr = $auth->getQrcodeStr($secret, 'zhansan', 'org');
    
    // todo: qrcode提供前端生成二维码
}

use Lizhijun\TOTP\TOTPAuth;

public function bindTOTP(){

    $secret = ''; // 上一步生成的 TOTP 密钥
    $code = '';   // 用户使用二次密码验证器扫码后,验证器生成`一次性数字验证密码`
    $auth = new TOTPAuth();
    
    $verifyResult = $auth->verifyCode($secret, $code);
    if ($verifyResult) {
        // todo: 验证成功 绑定 TOTP 密钥到用户信息
    } else {
    }
}



composer -vvv