/ci-google-authenticator

CodeIgniter library to create and verify Google Authenticator web service's secret codes.

Primary LanguagePHP

CodeIgniter Library: Google Authenticator

ci-google-authenticator

About this library

This CodeIgniter's library creates and verifies Google Authenticator web service's secret codes (2-Step Verification).

It can generate secrets, generate codes, validate codes and present a QR-Code for scanning the secret.

This library is a modified version of the PHPGangsta's class.

Its usage is recommended for CodeIgniter 2 or greater.

Google 2-Step Verification

Usage

Load the library

$this->load->library('GoogleAuthenticator');

Generate the secret and QR code

// generates the secret code
$secret = $this->googleauthenticator->createSecret();

// generates the QR code for the link the user's phone with the service
$qrCodeUrl = $this->googleauthenticator->getQRCodeGoogleUrl('Service Name', 'user@email.com', $secret);

// also, you can get a code to test the service
$oneCode = $this->googleauthenticator->getCode($secret);

Verify your phone's code

// get the user's phone code and the secret code that was generated, and verify
$checkResult = $this->googleauthenticator->verifyCode($secret, $code, 2); // 2 = 2*30sec clock tolerance

if ($checkResult) {
    echo 'OK';
} else {
    echo 'FAILED';
}

Ale Mohamad