Coder Social home page Coder Social logo

gauth's Introduction

GAuth : Google Authenticator Code Generator/Validation

Total Downloads

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!';
}
?>

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
$holder = '[email protected]';
$name = 'my-app-name';

$g = new \GAuth\Auth('your-initialization-code');
$qrCodeImageData = $g->generateQrImage($holder, $name, 200);

// To use in an image tag:
echo '<img src="data:image/png;base64,'.base64_encode($qrCodeImageData).'"/><br/><hr/>';

// 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:

gauth's People

Contributors

enygma avatar mattparker avatar ashleypinner avatar rmasters avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.