{"id":2351,"date":"2016-06-11T02:53:00","date_gmt":"2016-06-10T23:53:00","guid":{"rendered":"http:\/\/dima.fi\/blog\/?p=2351"},"modified":"2026-01-10T22:54:14","modified_gmt":"2026-01-10T20:54:14","slug":"totp-and-public-key-for-two-factor-authentication","status":"publish","type":"post","link":"https:\/\/dima.fi\/blog\/totp-and-public-key-for-two-factor-authentication\/","title":{"rendered":"TOTP and Public key for two factor authentication"},"content":{"rendered":"\n<p>Google, Facebook, Twitter, LinkedIn and many other sites have two-factor authentication. And I also want to have it in some of my projects.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>I use <a rel=\"noreferrer noopener\" aria-label=\"Authy (opens in a new tab)\" href=\"https:\/\/authy.com\/\" target=\"_blank\">Authy<\/a> desktop service and mobile app for getting the OTP password.<\/p>\n\n\n\n<p>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 &#8211; secret. These are the only guidelines that I need and are widely used.<\/p>\n\n\n\n<p>So I&#8217;ve created a PHP class that creates 16 chars long public key in 4&#215;4 chunks for easy reading and generates 6 digit password from the given public key. That it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">$tfa = new tfa();\n\n$pubkey = $tfa->getPubKey(); \/\/ WTLA NYJL ZDOR 5OVH\n\n$otp = $tfa->getOtp($pubkey); \/\/ 580733<\/code><\/pre>\n\n\n\n<p>Simple, isn&#8217;t it? The rest is in your hand.<\/p>\n\n\n\n<p>Get it from&nbsp;<a href=\"https:\/\/github.com\/dimamedia\/PHP-Simple-TOTP-and-PubKey\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Github: PHP Simple TOTP and PubKey<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2427,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/images.unsplash.com\/photo-1528660544347-95a93c58e424?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjF9","fifu_image_alt":"TOTP and Public key for two factor authentication","footnotes":""},"categories":[133],"tags":[138,136,137,135,134],"class_list":["post-2351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-devs","tag-authentication","tag-otp","tag-security","tag-totp","tag-web","has-thumbnail"],"_links":{"self":[{"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/posts\/2351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/comments?post=2351"}],"version-history":[{"count":3,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/posts\/2351\/revisions"}],"predecessor-version":[{"id":2380,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/posts\/2351\/revisions\/2380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/media\/2427"}],"wp:attachment":[{"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/media?parent=2351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/categories?post=2351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dima.fi\/blog\/wp-json\/wp\/v2\/tags?post=2351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}