Google authenticator 谷歌身份验证,实现动态口令

Google authenticator 谷歌身份验证,实现动态口令

google authenticator php 服务端

使用PHP类

require_once '../PHPGangsta/GoogleAuthenticator.php';

$ga = new PHPGangsta_GoogleAuthenticator(); //创建一个新的"安全密匙SecretKey" //把本次的"安全密匙SecretKey" 入库,和账户关系绑定,客户端也是绑定这同一个"安全密匙SecretKey"

$secret = $ga->createSecret();

echo "安全密匙SecretKey: ".$secret."\n\n";

$qrCodeUrl = $ga->getQRCodeGoogleUrl('www.iamle.com', $secret); //第一个参数是"标识",第二个参数为"安全密匙SecretKey" 生成二维码信息

echo "Google Charts URL for the QR-Code: ".$qrCodeUrl."\n\n"; //Google Charts接口 生成的二维码图片,方便手机端扫描绑定安全密匙SecretKey

$oneCode = $ga->getCode($secret); //服务端计算"一次性验证码"

echo "服务端计算的验证码是:".$oneCode."\n\n";

//把提交的验证码和服务端上生成的验证码做对比

//$secret 服务端的 "安全密匙SecretKey"

// $oneCode 手机上看到的 "一次性验证码"

// 最后一个参数 为容差时间,这里是2 那么就是 2* 30 sec 一分钟.

// 这里改成自己的业务逻辑

$checkResult = $ga->verifyCode($secret, $oneCode, 2);

if ($checkResult) {

  echo '匹配! OK';

} else {

echo '不匹配! FAILED';

}

服务端例子:

安全密匙SecretKey: NI5RHMWOTBIY6KP4

 Google Charts URL for the QR-Code: https://chart.googleapis.com/chart?chs=200×200&chld=M|0&cht=qr&chl=otpauth%3A%2F%2Ftotp%2Fwwek–www.iamle.com%3Fsecret%3DNI5RHMWOTBIY6KP4

服务端计算出的验证码是:255466 

匹配! OK

 

Google authenticator 手机客户端

Android移动设备

  在您手机的应用市场搜索“Google身份验证器”或“Google Authenticator”,下载安装即可。拥有Google身份验证器的市场有:Google Play;应用汇;安卓市场;百度移动应用;优亿市场;安智市场 等

iOS移动设备

  应用市场,搜索“Google Authenticator”,下载安装即可。

测试上面的例子

手机中的验证码 和 服务端的验证码 都是 255466 验证通过

 

转载于:https://www.cnblogs.com/jinxiblog/p/6692721.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值