Blogi loki päiväkirja
Dima's diary about anything
3D modelling, 3D printing, FPV, electronics, photography, life
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 a fast and simple solution. So I made my own.
I use Authy desktop service and mobile app for getting the OTP password.
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 other word – secret. These are the only guidelines that I need and are widely used.
So I’ve created a PHP class that creates 16 chars long public key in 4×4 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