leandrolugaresi/google-authenticator

此包已被放弃,不再维护。没有建议的替代包。

PHP版的Google Authenticator仓库

1.0.1 2014-10-08 21:49 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:39:44 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
    }