https://github.com/hoangphidev/google-2fa
🚀 Laravel package about Google Authenticator.
https://github.com/hoangphidev/google-2fa
2fa 2fa-security 2factor google-2fa google-authenticator laravel laravel-2fa laravel-framework laravel-package
Last synced: 3 months ago
JSON representation
🚀 Laravel package about Google Authenticator.
- Host: GitHub
- URL: https://github.com/hoangphidev/google-2fa
- Owner: hoangphidev
- License: mit
- Created: 2020-11-25T15:20:20.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-25T15:21:08.000Z (over 4 years ago)
- Last Synced: 2025-01-08T17:58:11.386Z (4 months ago)
- Topics: 2fa, 2fa-security, 2factor, google-2fa, google-authenticator, laravel, laravel-2fa, laravel-framework, laravel-package
- Language: PHP
- Homepage: https://packagist.org/packages/hoangphi/google-2fa
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## Google Authenticator Laravel Package
* Copyright (c) 2020, [Phi Hoang JSC](https://github.com/hoangphidev)
* Author: Phi Hoang, [@hoangphidev](https://github.com/hoangphidev) and [contributors](https://github.com/hoangphidev/google-2fa/graphs/contributors)
* Licensed under the MIT License.[](https://packagist.org/packages/hoangphi/google-2fa)
[](https://packagist.org/packages/hoangphi/google-2fa)## Install
```shell
composer require hoangphi/google-2fa
```## Config
Add column `secret_code`
```shell
php artisan google-2fa:make
```### Example
Add column `secret_code` into table `users`
```shell
php artisan google-2fa:make users
```We have file `database\migrations\{time_stamp}_add_secret_code_to_users.php`
```php
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
```shell
php artisan migrate
```You must migrate table `users` before.
## Usage
See following example:
```php
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';
}
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Security
If you discover any security-related issues, please email [[email protected]](mailto:[email protected]) instead of using the issue tracker.
## Credits
- [Phi Hoang](https://github.com/hoangphidev)
- [All Contributors](../../contributors)## References
- [Google Authenticator PHP class](https://github.com/PHPGangsta/GoogleAuthenticator)
## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).