Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enygma/gauth
Google Authenticator Code Validation and Generation
https://github.com/enygma/gauth
gauth google-authenticator php
Last synced: 3 days ago
JSON representation
Google Authenticator Code Validation and Generation
- Host: GitHub
- URL: https://github.com/enygma/gauth
- Owner: enygma
- License: mit
- Created: 2013-01-07T20:58:20.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-11-14T11:46:14.000Z (about 7 years ago)
- Last Synced: 2024-12-18T18:07:19.601Z (11 days ago)
- Topics: gauth, google-authenticator, php
- Language: PHP
- Size: 17.6 KB
- Stars: 75
- Watchers: 9
- Forks: 12
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
GAuth : Google Authenticator Code Generator/Validation
=========================[![Total Downloads](https://img.shields.io/packagist/dt/enygma/gauth.svg?style=flat-square)](https://packagist.org/packages/enygma/gauth)
The `GAuth` library is designed to generate and validate codes compatible with the
Google Authenticator tools.### Installation via Composer:
Include in your `composer.json` file:
```
{
"require": {
"enygma/gauth": "dev-master"
}
}
```#### Getting Started
To get started using the Google Authenticator with your application, you'll need to make an
initialization key (using `generateCode`) and save that to your app's settings. This is the
code you'll share with your users when they're trying to set up their client for your system.Then, when they log in you have them enter in the latest code listed for your application for
thier account.**NOTE:** This tool offers a "window of opportunity" for the codes of 2 seconds forward and
backward of the current timestamp, just in case things are a bit off. You can change this with
the `setRange` method:```php
setRange(3);
?>
```#### To generate a new code:
```php
generateCode();
var_dump($code);?>
```#### To validate a code
```php
validateCode($code);if ($verify == true) {
echo 'User code verified!';
} else {
echo 'User code invalid!';
}
?>
```#### To get the QR code for the application
You can also use the tool to get the URL for a QR code users can scan to add your application to their Authenticator client. The call to `generateQrImage` returns the actual image data for you to use as you wish, either to embed in an `img` tag or save to a file:
```php
generateQrImage($holder, $name, 200);// To use in an image tag:
echo '
';// Or just save to a file
file_put_contents('/path/to/qr-file.png', $qrCodeImageData);
?>
```The library uses internal QR code generation, not the Google Charts API many similar libraries use.
#### More info:
- [Google TOTP Two-factor Authentication for PHP](http://www.idontplaydarts.com/2011/07/google-totp-two-factor-authentication-for-php/)
- [Links to client for smartphones](http://support.google.com/accounts/bin/answer.py?hl=en&answer=1066447)