- Copyright (c) 2020, Phi Hoang JSC
- Author: Phi Hoang, @hoangphidev and contributors
- Licensed under the MIT License.
composer require hoangphi/google-2fa
Add column secret_code
php artisan google-2fa:make <table_name>
Add column secret_code
into table users
php artisan google-2fa:make users
We have file database\migrations\{time_stamp}_add_secret_code_to_users.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddSecretCodeToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('secret_code')->nullable()->after('id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('secret_code');
});
}
}
Run migrate
command
php artisan migrate
You must migrate table users
before.
See following example:
use HoangPhi\GoogleAuthenticator\GoogleAuthenticator;
$googleAuthenticator = new GoogleAuthenticator();
$secret = $googleAuthenticator->createSecret();
echo "Secret is: " . $secret . "\n\n";
$qrCodeUrl = $googleAuthenticator->getQRCodeGoogleUrl('Blog', $secret);
echo "Google Charts URL for the QR-Code: ".$qrCodeUrl."\n\n";
$oneCode = $googleAuthenticator->getCode($secret);
echo "Checking Code '$oneCode' and Secret '$secret':\n";
$checkResult = $googleAuthenticator->verifyCode($secret, $oneCode, 2); // 2 = 2*30sec clock tolerance
if ($checkResult) {
echo 'OK';
} else {
echo 'FAILED';
}
Please see CHANGELOG for more information what has changed recently.
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
The Laravel framework is open-sourced software licensed under the MIT license.