项目作者: hoangphidev

项目描述 :
🚀 Laravel package about Google Authenticator.
高级语言: PHP
项目地址: git://github.com/hoangphidev/google-2fa.git
创建时间: 2020-11-25T15:20:20Z
项目社区:https://github.com/hoangphidev/google-2fa

开源协议:MIT License

下载


Google Authenticator Laravel Package

Latest Version on Packagist
Total Downloads

Install

  1. composer require hoangphi/google-2fa

Config

Add column secret_code

  1. php artisan google-2fa:make <table_name>

Example

Add column secret_code into table users

  1. php artisan google-2fa:make users

We have file database\migrations\{time_stamp}_add_secret_code_to_users.php

  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class AddSecretCodeToUsers extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. Schema::table('users', function (Blueprint $table) {
  15. $table->string('secret_code')->nullable()->after('id');
  16. });
  17. }
  18. /**
  19. * Reverse the migrations.
  20. *
  21. * @return void
  22. */
  23. public function down()
  24. {
  25. Schema::table('users', function (Blueprint $table) {
  26. $table->dropColumn('secret_code');
  27. });
  28. }
  29. }

Run migrate command

  1. php artisan migrate

You must migrate table users before.

Usage

See following example:

  1. use HoangPhi\GoogleAuthenticator\GoogleAuthenticator;
  2. $googleAuthenticator = new GoogleAuthenticator();
  3. $secret = $googleAuthenticator->createSecret();
  4. echo "Secret is: " . $secret . "\n\n";
  5. $qrCodeUrl = $googleAuthenticator->getQRCodeGoogleUrl('Blog', $secret);
  6. echo "Google Charts URL for the QR-Code: ".$qrCodeUrl."\n\n";
  7. $oneCode = $googleAuthenticator->getCode($secret);
  8. echo "Checking Code '$oneCode' and Secret '$secret':\n";
  9. $checkResult = $googleAuthenticator->verifyCode($secret, $oneCode, 2); // 2 = 2*30sec clock tolerance
  10. if ($checkResult) {
  11. echo 'OK';
  12. } else {
  13. echo 'FAILED';
  14. }

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security-related issues, please email hoangphidev@gmail.com instead of using the issue tracker.

Credits

References

License

The Laravel framework is open-sourced software licensed under the MIT license.