truesocialmetrics/google-authenticator

PHP版本的Google Authenticator仓库

1.3.0 2020-04-03 08:08 UTC

This package is auto-updated.

Last update: 2024-08-29 05:22:25 UTC


README

[已弃用] 请使用antonioribeiro/google2fa代替!

Latest Stable Version Total Downloads Latest Unstable Version License Codeship Status for leandro-lugaresi/google-authenticator

简介

这是一个用于将网站与Google Authenticator集成的模块。

要求

安装

  1. 将此项目添加到您的composer.json中
    "require": {
        "leandrolugaresi/google-authenticator": "1.0.*"
    }
  1. 现在运行以下命令让composer下载仓库:
    $ php composer.phar update

用法

步骤 1 - 注册应用程序

显示二维码和表单

    $googleAuth = new \GoogleAuthenticator\GoogleAuthenticator();
    $googleAuth->setIssuer('YourApplicationName');
    //save the secretKey to register after
    $_SESSION['secretKeyTemp'] = $googleAuth->getSecretKey();

    // Show the qrcode to register
    //this param is an identifier of the user in this application
    echo $googleAuth->getQRCodeUrl($user->username.'@YourApplicationName');

验证表单中的代码并保存此用户的secretKey

    $google = new GoogleAuthenticator($_SESSION['secretKeyTemp']);
    $userSubmitCode = $_POST['codeFoo'];
    if ($google->verifyCode($userSubmitCode)) {
        //save the secretKey of this user
    }

步骤 2 - 登录时验证代码

    $google = new GoogleAuthenticator($user->getSecretKey());
    $userSubmitCode = $_POST['codeFoo'];

    // Verify Code
    if ($google->verifyCode($userSubmitCode)) {

        // OK - aloowed login
    }