-1
A
回答
0
Step 1) Create a unique secret code of length 16 characters.
PHPGangsta provides wrapper class for Google Authenticator. You can download using composer.
curl -sS https://getcomposer.org/installer | php
php composer.phar require phpgangsta/googleauthenticator:dev-master
Use the below code to generate the secret code.
<?php
require 'vendor/autoload.php';
$authenticator = new PHPGangsta_GoogleAuthenticator();
$secret = $authenticator->createSecret();
echo "Secret: ".$secret;
?>
Step 2) Create a QR code withe the generated secret.
We need to prepare a QR code using the secret. If you want to read more about QR code generation for Google Authenticator. Github Wiki
You can use any QR code generator to generate the QR code, For this demo I am using Google charts.
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require 'vendor/autoload.php';
$authenticator = new PHPGangsta_GoogleAuthenticator();
$secret = $authenticator->createSecret();
echo "Secret: ".$secret."\n"; //save this at server side
$website = 'http://hayageek.com'; //Your Website
$title= 'Hayageek';
$qrCodeUrl = $authenticator->getQRCodeGoogleUrl($title, $secret,$website);
echo $qrCodeUrl;
?>
Step 3) Generate TOTP (Time-Based One time password) using Google Authenticator App
Download the Google Authenticator app from Google Play or AppStore
Open the app and Click on ‘+’ Button, and scan the QR code generated using Google Charts. Authenticator app generates the TOTP for your website. TOTP will change for every 30 secs.
Two factor authentication with Google Authenticator
Step 4) Verifying OTP at server side
<?php
require 'vendor/autoload.php';
$authenticator = new PHPGangsta_GoogleAuthenticator();
$secret = '3JMZE4ASZRIISJRI'; //This is used to generate QR code
$otp = '183036' ;//Generated by Authenticator.
$tolerance = 0;
//Every otp is valid for 30 sec.
// If somebody provides OTP at 29th sec, by the time it reaches the server OTP is expired.
//So we can give tolerance =1, it will check current & previous OTP.
// tolerance =2, verifies current and last two OTPS
$checkResult = $authenticator->verifyCode($secret, $otp, $tolerance);
if ($checkResult)
{
echo 'OTP is Validated Succesfully';
} else {
echo 'FAILED';
}
?>
源代碼參考以下鏈接:http://hayageek.com/two-factor-authentication-with-google-authenticator-php/
+0
謝謝你的代碼..我會試試這個,如果有任何澄清,請回復你。 –
相關問題
- 1. 雙因素認證機制
- 2. Heroku雙因素認證多設備?
- 3. 谷歌認證
- 4. 我可以利用谷歌等雙因素認證來驗證用戶訪問我的網站嗎?
- 5. 雙因素認證如何與隨機數一起工作?
- 6. 谷歌認證使用azure服務
- 7. 使用JavaScript和PHP與谷歌認證用戶
- 8. 如何使用ASP.net Identity 2.0設置雙因素身份驗證?
- 9. 更改雙因素認證休息的Heroku的API調用
- 10. 的Android:谷歌認證
- 11. 谷歌Gmail API - 認證
- 12. 沒有Passport.js谷歌+認證
- 13. 谷歌認證的AspNetCore.Identity
- 14. 谷歌認證的困難
- 15. xcode谷歌認證swift 3
- 16. 谷歌認證服務
- 17. Keyrock啓用雙因素身份驗證
- 18. 更改谷歌默認的認證重定向 - C#(谷歌liblary)
- 19. 使用谷歌圖表使用PHP和MySQL創建圖表?
- 20. VSO - 2因素認證
- 21. 使用數字證書進行雙因素身份驗證
- 22. 如何使用雙因子數據創建表格
- 23. 谷歌應用引擎認證
- 24. Gdata python谷歌應用程序認證
- 25. 如何創建谷歌聯繫人?
- 26. 如何創建谷歌效果?
- 27. 如何創建谷歌地圖結構
- 28. 創建認證
- 29. Twilio SMs雙因素身份驗證
- 30. Identity Server 3雙因素身份驗證
你有什麼迄今所做? – Aj334
我仍然沒有開始。因爲我不知道這是怎麼回事? –
你可能想看到這個答案http://stackoverflow.com/questions/16908124/google-two-factor-authentication-tutorial-for-codeigniter –