PHPackages                             renzhifan/laravel-google-authenticator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. renzhifan/laravel-google-authenticator

ActiveLibrary

renzhifan/laravel-google-authenticator
======================================

Laravel 5 GoogleAuthenticator Package

v1.0(7y ago)16MITPHP

Since Jan 11Pushed 7y agoCompare

[ Source](https://github.com/renzhifan/laravel-google-authenticator)[ Packagist](https://packagist.org/packages/renzhifan/laravel-google-authenticator)[ RSS](/packages/renzhifan-laravel-google-authenticator/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

Google 身份验证器与两步验证功能配合，可在您登录 Google 帐户时为您平添一重安全保障。启用两步验证之后，当您登录帐户时，需要提供密码和此应用生成的验证码。配置完成后，无需网络连接或蜂窝连接即可获得验证码。APP中使用如下： [![手机使用google authenticator](https://github.com/earnp/laravel-google-authenticator/raw/master/src/images/google/authenticator.jpg)](https://github.com/earnp/laravel-google-authenticator/blob/master/src/images/google/authenticator.jpg)

为什么使用两步认证
=========

[](#为什么使用两步认证)

1. 相对于验证码，安全很多；几乎是不会存在破解的方法
2. 验证码有时候无法识别，不方便操作
3. 一机一码，不会存在账号盗用的问题
4. 动态验证，每30秒生产一个验证码，安全更加保障

开发前的准备
======

[](#开发前的准备)

1. 安装Laravel
2. 安装二维码生成器`QrCode`,没有安装也可以，接下来会安装

安装拓展
====

[](#安装拓展)

1、运行如下代码安装拓展包：

```
composer require "renzhifan/laravel-google-authenticator:dev-master"
# 安装二维码生成器
composer require simplesoftwareio/simple-qrcode 1.3.*

```

3.等待下载安装完成，需要在`config/app.php`中注册服务提供者同时注册下相应门面：

```
'providers' => [
    //........
    Renzhifan\GoogleAuthenticator\GoogleAuthenticatorServiceprovider::class,
    SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class,
],

'aliases' => [
     //..........
    'Google' => Renzhifan\GoogleAuthenticator\Facades\GoogleAuthenticator::class,
    'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class
],
```

服务注入以后，如果要使用自定义的配置，还可以发布配置文件到config/views目录：

```
php artisan vendor:publish
```

使用
==

[](#使用)

使用方法非常简单，主要为生成验证码和教研验证码

### 1、生产验证码

[](#1生产验证码)

生产验证码使用`CreateSecret`即可，你需要将其内容生成二维码供手机APP扫描,具体内容在`google.blade.php`中已经配置成功

```
// 创建谷歌验证码
$createSecret = Google::CreateSecret();
// 您自定义的参数，随表单返回
$parameter = [["name"=>"usename","value"=>"123"]];
return view('login.google.google', ['createSecret' => $createSecret,"parameter" => $parameter]);

```

### 2、校验验证码

[](#2校验验证码)

校验验证码一般用于绑定，登录认证中，使用`CheckCode`方法即可，需要传入`secrect`和`onecode`即验证码即可进行校验，第一个为`secrect`；返回`true`或`false`

```
if(Google::CheckCode($google,$request->onecode)) {
    // 绑定场景：绑定成功，向数据库插入google参数，跳转到登录界面让用户登录
    // 登录认证场景：认证成功，执行认证操作
    dd("认证成功");
}
else
{
    // 绑定场景：认证失败，返回重新绑定，刷新新的二维码
    return back()->with('msg','请正确输入手机上google验证码 ！')->withInput();
    // 登录认证场景：认证失败，返回重新绑定，刷新新的二维码
    return back()->with('msg','验证码错误，请输入正确的验证码 ！')->withInput();
}

```

这里有一个具体的实际事例：

```
use Google;

if ($request->isMethod('post')) {
    if (empty($request->onecode) && strlen($request->onecode) != 6) return back()->with('msg','请正确输入手机上google验证码 ！')->withInput();
    // google密钥，绑定的时候为生成的密钥；如果是绑定后登录，从数据库取以前绑定的密钥
    $google = $request->google;
    // 验证验证码和密钥是否相同
    if(Google::CheckCode($google,$request->onecode)) {
        // 绑定场景：绑定成功，向数据库插入google参数，跳转到登录界面让用户登录
        // 登录认证场景：认证成功，执行认证操作
        dd("认证成功");
    }
    else
    {
        // 绑定场景：认证失败，返回重新绑定，刷新新的二维码
        return back()->with('msg','请正确输入手机上google验证码 ！')->withInput();
        // 登录认证场景：认证失败，返回重新绑定，刷新新的二维码
        return back()->with('msg','验证码错误，请输入正确的验证码 ！')->withInput();
    }
}
else
{
    // 创建谷歌验证码
    $createSecret = Google::CreateSecret();
    // 您自定义的参数，随表单返回
    $parameter = [["name"=>"usename","value"=>"123"]];
    return view('login.google.google', ['createSecret' => $createSecret,"parameter" => $parameter]);
}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2679d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ee0c317fe94bfeebc29c512bdf75ae5b65d5f3188fa2d42d3ce664da53e03d7?d=identicon)[renzhifan](/maintainers/renzhifan)

---

Top Contributors

[![renzhifan](https://avatars.githubusercontent.com/u/29975218?v=4)](https://github.com/renzhifan "renzhifan (1 commits)")

### Embed Badge

![Health badge](/badges/renzhifan-laravel-google-authenticator/health.svg)

```
[![Health](https://phpackages.com/badges/renzhifan-laravel-google-authenticator/health.svg)](https://phpackages.com/packages/renzhifan-laravel-google-authenticator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
