TOTP and Public key for two factor authentication

Google, Facebook, Twitter, LinkedIn and many other sites have two factor authentication. And I also want to have it in some of my projects.

While searching the internet, I found many solutions. All of them are somehow complicated or stuffed with unnecessary features for me. I want fast and simple solution. So I made my own.

I use Google Authenticator on my phone and QuickAuth on my Pebble Time smartwatch.

These apps generate 6 digit TOTP (Time based one-time password) for 30 second period. Google requires at least 16 chars long public key or in another word - secret. These are the only guidelines that I need and are widely used.

So I've created php class that creates 16 chars long public key in 4x4 chunks for easy reading and generates 6 digit password from the given public key. That it.

$tfa = new tfa();

$pubkey = $tfa->getPubKey(); // WTLA NYJL ZDOR 5OVH

$otp = $tfa->getOtp($pubkey); // 580733

Simple, isn't it? The rest is in your hand.

Get it from Github: PHP Simple TOTP and PubKey

0 comments

Your comment

Write the number six hundreds and seventy-eight: