PHP设置谷歌验证器(Google Authenticator)实现操作二步验证
使用说明:开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码。实现Google Authenticator功能需要服务器端和客户端的支持。服务器端负责密钥的生成、验证一次性密码是否正确。客户端记录密钥后生成一次性密码。
下载谷歌验证类库文件放到项目合适位置(我这边放在项目Vender下面)
https://github.com/PHPGangsta/GoogleAuthenticator
PHP代码示例:
//引入谷歌验证器类
vendor('googleAuth.GoogleAuthenticator-master.PHPGangsta.GoogleAuthenticator');
$ga = new \PHPGangsta_GoogleAuthenticator(); //这是生成的密钥,每个用户唯一一个,为用户保存起来用于验证
$secret = $ga->createSecret();
//echo $secret; //下面为生成二维码,内容是一个URI地址(otpauth://totp/账号?secret=密钥&issuer=标题)
$qrCodeUrl = $ga->getQRCodeGoogleUrl('luokakale', $secret, 'googleVerify');
//echo $qrCodeUrl;
将上面生成的二维码地址放入网页img标签里面即可,示例图展示如下:

接下来就是客户端谷歌验证APP扫码绑定后进行输码验证,验证PHP代码示例:
//引入谷歌验证器类
vendor('googleAuth.GoogleAuthenticator-master.PHPGangsta.GoogleAuthenticator');
$ga = new \PHPGangsta_GoogleAuthenticator(); //下面为验证参数
$code = $_GET['code'];//客户提交上来的谷歌验证APP里面对应的验证码 //该用户绑定谷歌验证生成的唯一秘钥
$secret = 'VO2WA6NG3XZZEU4E'; //验证用户提交的验证码是否正确
$checkResult = $ga->verifyCode($secret, $code, 1); if ($checkResult) {
echo 'SUCCESS';
} else {
echo 'FAILED';
}
验证成功即客户绑定谷歌验证成功。该谷歌验证可用于客户登陆支付个人设置等各种场景。
本文属原创内容,为了尊重他人劳动,转载请注明本文地址:
https://www.cnblogs.com/luokakale/p/11384838.html
PHP设置谷歌验证器(Google Authenticator)实现操作二步验证的更多相关文章
- java实现谷歌二步验证 (Google Authenticator)
准备: 一个谷歌二步验证APP, 我用的是ios 身份宝 资料: 1.Google Authenticator 原理及Java实现 //主要参考 https://blog.csdn.net/li ...
- Google 推出全新的两步验证机制
近日 Google 在官方的 Apps Updates 博客公布了全新的两步验证功能--Google 提示,新的功能通过与 Google App 联动,进一步将验证确认工作缩减到仅有两步,同时支持 A ...
- Python使用otp实现二步验证
https://www.cnblogs.com/lori/p/11077161.html https://blog.coding.net/blog/two-factor-authentication ...
- TOTP算法实现二步验证
概念 TOTP算法(Time-based One-time Password algorithm)是一种从共享密钥和当前时间计算一次性密码的算法. 它已被采纳为Internet工程任务组标准RFC 6 ...
- 谷歌制图服务(Google Chart)接口生成二维码
Google公布了制图服务(Google Chart)的接口,这项服务用起来相当简单,只使用浏览器就可以用来为统计数据自动生成图片. 目前谷歌制图服务提供折线图.条状图.饼图.Venn图.散点图.二维 ...
- Google Authenticator(谷歌身份验证器)
<!DOCTYPE html>Google Authenticator(谷歌身份验证器) ] Google Authenticator(谷歌身份验证器) Google Authentica ...
- 计算机网络安全 —— C# 使用谷歌身份验证器(Google Authenticator)(五)
一.Google Authenticator 基本概念 Google Authenticator是谷歌推出的一款动态口令工具,旨在解决大家Google账户遭到恶意攻击的问题,在手机端生成动态口令后, ...
- 谷歌验证器的原理及JS实现
阅读本篇文章你可以了解到谷歌验证器的实现原理,并且可以自己使用node.js实现支持谷歌验证器的两步验证. 这两年发现身边的很多应用和网站纷纷支持两步验证,并且呼吁用户使用两步验证. 并且发现,除了A ...
- 谷歌验证 (Google Authenticator) 的实现原理是什么?
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:徐小花链接:http://www.zhihu.com/question/20462696/answer/18731073来源: ...
随机推荐
- java使用Sonic 算法对音频变速不变声、变调、调整音量
依赖库:https://github.com/waywardgeek/sonic 基础库:Sonic.java /* Sonic library Copyright 2010, 2011 Bill C ...
- 【NANO】引脚说明
http://bbs.eeworld.com.cn/forum.php?mod=viewthread&tid=489650&page=1
- 【Leetcode_easy】908. Smallest Range I
problem 908. Smallest Range I solution: class Solution { public: int smallestRangeI(vector<int> ...
- [Google] 人和自行车匹配
2D平面上,有m个人(P),n辆自行车(B),还有空白(O)满足以下条件1.m < n. 2.不存在两个人,到同一辆自行车距离相等, 距离用abs(x1-x2) + abs(y1-y2)定义3. ...
- 内存运行PE文件
内存中运行文件 拿exe并在HxD或010中打开 - cntrl+a copy as C 粘贴到encrypt.cpp 编译并运行encrypt.cpp - 创建shellcode.txt 从shel ...
- 3.WXML语法
标签必须完全闭合 大小写敏感
- Deepin 15.11 install nvidia dirver[mei you an zhuang shu ru fa]
1.firstly, exec: sudo vim /etc/modprobe.d/blacklist-nouveau.conf[create], and input [blacklist nouve ...
- Java的设计模式(6)— 模板模式
定义一个操作中算法的骨架,将一些步骤放在子类实现,使得子类可以不改变一个算法结构即子类可以重定义该算法的某些特定步骤. 主要有两个角色: 1. 抽象模板 :是一个抽象类,并实现了一个具体模板方法,这个 ...
- AVR单片机教程——流水灯
上次我们用 delay 函数与 while 循环实现了一个LED的闪烁.这一次我们把所有LED加入进来,让它们依次闪烁,形成流水灯的效果. 开发板上有4个LED,我们可以用不多的语句把循环体直接描述出 ...
- 数据结构-链式栈c++
栈的最基本特点先进后出,本文简单介绍一下用c++写的链式栈 头文件 #ifndef LINKEDSTACK_H #define LINKEDSTACK_H template<class T> ...