定制 rikudou/google-authenticator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rikudou/google-authenticator

Composer 安装命令:

composer require rikudou/google-authenticator

包简介

Simple OTP generator compatible with Google Authenticator

README 文档

README

Really simple, can be integrated in pretty much anything.

Installation

Include rikudou/google-authenticator in your composer dependencies, e.g.: composer require rikudou/google-authenticator.

Usage

<?php

use rikudou\GoogleAuthenticator\Authenticator;

// create a secret key, you can than store it in db or whatever
$secretKey = Authenticator::generateSecret(); // holds something like 4O7LDGME6HHINEP7

// get otp code
$authenticator = new Authenticator($secretKey);
$otpCode = $authenticator->getCode(); // holds a string with six digits number, e.g. 408532

// verify submitted code
$userSubmittedCode = $_POST['2facode']; // just an example, get the code however you want
$isCorrect = $authenticator->verify($userSubmittedCode); // holds true or false

And that's it, simple as that.

Handling exceptions

There are two cases where exception can be thrown.

<?php

use rikudou\GoogleAuthenticator\Authenticator;
use rikudou\GoogleAuthenticator\AuthenticatorException;

try {
    $secret = Authenticator::generateSecret(200);
} catch (AuthenticatorException $exception) {
    switch ($exception->getCode()) {
        case AuthenticatorException::INVALID_SECRET_LENGTH:
            // Exception message: "Could not create secret, length invalid. Valid value is an integer between 16 and 128, 200 given"
            break;
        case AuthenticatorException::NO_RANDOMNESS_SOURCE:
            // Exception message: "No randomness source for 'random_int()' found"
            // This should not happen on any modern system
            break;
    }
}

And that's all, folks!

统计信息

  • 总下载量: 232
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2018-02-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固