ci-google-authenticator
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.
- Google 2-Step Verification
- Google Authenticator mobile app:
This library is a modified version of the PHPGangsta's class.
Its usage is recommended for CodeIgniter 2 or greater.
$this->load->library('GoogleAuthenticator');
// 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);
// 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';
}