Skip to content
/ gauth Public
forked from enygma/gauth

Google Authenticator Code Validation and Generation

License

Notifications You must be signed in to change notification settings

wyiemay/gauth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GAuth : Google Authenticator Code Generator/Validation

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
$g = new \GAuth\Auth();

// set it to 3 seconds
$g->setRange(3);
?>

To generate a new code:

<?php

require_once 'vendor/autoload.php';

// Useful for creating a new Initialization key if needed
$g = new \GAuth\Auth();
$code = $g->generateCode();
var_dump($code);

?>

To validate a code

<?php

$code = 'code-inputted-from-user';

$g = new \GAuth\Auth('your-initialization-code');
$verify = $g->validateCode($code);

if ($verify == true) {
    echo 'User code verified!';
} else {
    echo 'User code invalid!';
}
?>

More info:

About

Google Authenticator Code Validation and Generation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published