https://github.com/atomjoy/google-authenticator
2FA two-step verification with php and Google Authenticator in Laravel.
https://github.com/atomjoy/google-authenticator
google-authenticator google-authenticator-php
Last synced: 2 months ago
JSON representation
2FA two-step verification with php and Google Authenticator in Laravel.
- Host: GitHub
- URL: https://github.com/atomjoy/google-authenticator
- Owner: atomjoy
- Created: 2024-02-22T22:34:14.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-22T22:35:42.000Z (over 2 years ago)
- Last Synced: 2025-06-01T11:35:18.890Z (about 1 year ago)
- Topics: google-authenticator, google-authenticator-php
- Language: PHP
- Homepage: https://github.com/atomjoy/google-authenticator
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP Google Authenticator
2FA two-step verification with php and Google Authenticator in Laravel.
## Install
```sh
composer require atomjoy/google-authenticator
```
## GoogleAuthenticator in Laravel
How to generate code from user secret like in GoogleAuthenticator on Android but from php script.
```php
createSecret();
// QR-Code image
$url = $ga->getQRCodeUrl('Appname:user@example.com', $secret);
// Show user qr-code
echo "
New secret is: " . $secret . "
";
echo 'Google Charts URL for the QR-Code:
';
echo '
';
} else {
// Generate code from user secret like in GoogleAuthenticator on Android but from php script
// Past this code in github 2fa confirm code form
$code = $ga->getCode($secret);
echo "Checking code " . $code . " and Secret " . $secret . " use this code in 2fa on github, facebook, ...
";
// Confirm code (allow 2*30sec clock tolerance)
if ($ga->verifyCode($secret, $code, 2)) {
echo '
OK
';
} else {
echo 'FAILED
';
}
}
});
```
## Enable github two factor with php script
```sh
php artisan serve
# 1. Get and save generated secret when enabling two-factor authentication in panel settings
# QR-code example github_2fa_secret: FA7DKAS2MK6SH3BN
# 2. Enable or Login with 2fa secret
# Get 6-digit code and past in github 2fa form 😄 (refresh every 30 seconds)
http://127.0.0.1:8000/test/2fa/google/{github_2fa_secret}
```