2013-04-21 151 views
1

有人可以指导我在实施Google身份验证应用程序时做了什么错误吗? 以下是我没有成功尝试:谷歌身份验证应用程序的双向身份验证

1#创建密钥

$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; // allowed characters in Base32 
$secret = ''; 
for ($i = 0; $i < 16; $i++) 
{ $secret .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); } 

2#创建通过谷歌服务(介绍+密钥)QR码和扫描智能手机和6位数字每30秒由谷歌认证应用程序生成

3#。现在,我想验证它...([使用base32算法中] [1])

$tm = floor(time()/30); // for time purpose 
$secretkey=Base32::decode($secretkey); // return blank 
$time=chr(0).chr(0).chr(0).chr(0).pack('N*',$tm+$i); 

// Hash it with users secret key 
$hm = hash_hmac('SHA1', $time, $secretkey, true); 

// Use last nipple of result as index/offset 
$offset = ord(substr($hm,-1)) & 0x0F; 

// grab 4 bytes of the result 
$hashpart=substr($hm,$offset,4); 

// Unpak binary value 
$value=unpack("N",$hashpart); 
$value=$value[1]; 

// Only 32 bits 
$value = $value & 0x7FFFFFFF; 
$value = $value % 1000000; 

上面的代码是基于其他来源(WordPress的谷歌认证的应用程序).​​.....但它不是加工。

$ secretkey = Base32 :: decode($ secretkey); 总是返回空白(空)

有没有另一种方法来验证或实现基于时间的算法?或者我可以阅读有关如何为网站进行双向身份验证的代码的链接?

感谢您的提前和明显的努力。 (我认为它是一种安全的目的问题,所以我已经把这里的,而不是计算器.. :))

+0

@Ladadadada:感谢改善.. :) – 2013-04-21 19:31:12

+0

TOTP的RFC包含一些可以用作基础的java代码(它对我有用)。 https://tools.ietf.org/html/rfc6238 – 2013-04-21 20:48:09

+1

你见过https://github.com/chregu/GoogleAuthenticator.php吗? – Maerlyn 2013-04-21 21:51:00

回答

1

实现使用github.com/chregu/GoogleAuthenticator.php