{"id":2118,"date":"2025-09-24T12:18:52","date_gmt":"2025-09-24T12:18:52","guid":{"rendered":"https:\/\/itxperts.co.in\/blog\/?p=2118"},"modified":"2026-01-11T07:17:18","modified_gmt":"2026-01-11T07:17:18","slug":"google-authenticator-2fa-login-php","status":"publish","type":"post","link":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/","title":{"rendered":"How to Implement Google Authenticator 2FA Login in PHP"},"content":{"rendered":"\n<p>Passwords alone aren\u2019t enough to keep your application secure. Attackers often crack or steal credentials, which is why <strong>Two-Factor Authentication (2FA)<\/strong> has become standard in modern applications.<\/p>\n\n\n\n<p>In this tutorial, we\u2019ll build a <strong>PHP login system with Google Authenticator<\/strong> that requires both a password and a one-time code from the user\u2019s phone.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PHP 7.4+ with MySQL\/MariaDB<\/li>\n\n\n\n<li>Composer installed<\/li>\n\n\n\n<li>Basic understanding of PHP sessions and authentication<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Install Google Authenticator Library<\/h2>\n\n\n\n<p>Run this in your project folder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require sonata-project\/google-authenticator\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Database Setup<\/h2>\n\n\n\n<p>Create a table for storing users and their 2FA secret.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE users (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    username VARCHAR(100) NOT NULL,\n    password VARCHAR(255) NOT NULL,\n    secret VARCHAR(255) DEFAULT NULL\n);\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Registration with QR Code<\/h2>\n\n\n\n<p>When a user registers, generate a secret key and QR code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ register.php\nrequire 'vendor\/autoload.php';\nuse Sonata\\GoogleAuthenticator\\GoogleAuthenticator;\nuse Sonata\\GoogleAuthenticator\\GoogleQrUrl;\n\n$pdo = new PDO(\"mysql:host=localhost;dbname=yourdb\", \"root\", \"\");\n\n\/\/ Handle registration\nif ($_SERVER&#91;'REQUEST_METHOD'] === 'POST') {\n    $username = $_POST&#91;'username'];\n    $password = password_hash($_POST&#91;'password'], PASSWORD_BCRYPT);\n\n    $g = new GoogleAuthenticator();\n    $secret = $g-&gt;generateSecret();\n\n    $stmt = $pdo-&gt;prepare(\"INSERT INTO users (username, password, secret) VALUES (?, ?, ?)\");\n    $stmt-&gt;execute(&#91;$username, $password, $secret]);\n\n    $qrCodeUrl = GoogleQrUrl::generate($username, $secret, 'MySecureApp');\n}\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;&lt;title&gt;Register&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;\n&lt;h2&gt;Register&lt;\/h2&gt;\n&lt;form method=\"post\"&gt;\n    Username: &lt;input type=\"text\" name=\"username\" required&gt;&lt;br&gt;\n    Password: &lt;input type=\"password\" name=\"password\" required&gt;&lt;br&gt;\n    &lt;button type=\"submit\"&gt;Register&lt;\/button&gt;\n&lt;\/form&gt;\n\n&lt;?php if (!empty($qrCodeUrl)): ?&gt;\n    &lt;h3&gt;Scan this QR Code in Google Authenticator&lt;\/h3&gt;\n    &lt;img src=\"&lt;?= $qrCodeUrl ?&gt;\"&gt;\n&lt;?php endif; ?&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49 After registration, users must scan the QR code in the <strong>Google Authenticator app<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Login with Password + OTP<\/h2>\n\n\n\n<p>First, verify username\/password. If correct, ask for OTP.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ login.php\nrequire 'vendor\/autoload.php';\nsession_start();\n\n$pdo = new PDO(\"mysql:host=localhost;dbname=yourdb\", \"root\", \"\");\n\nif ($_SERVER&#91;'REQUEST_METHOD'] === 'POST' &amp;&amp; isset($_POST&#91;'username'])) {\n    $username = $_POST&#91;'username'];\n    $password = $_POST&#91;'password'];\n\n    $stmt = $pdo-&gt;prepare(\"SELECT * FROM users WHERE username=?\");\n    $stmt-&gt;execute(&#91;$username]);\n    $user = $stmt-&gt;fetch();\n\n    if ($user &amp;&amp; password_verify($password, $user&#91;'password'])) {\n        $_SESSION&#91;'pending_user'] = $user;\n        header(\"Location: verify.php\");\n        exit;\n    } else {\n        echo \"\u274c Invalid username or password\";\n    }\n}\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;&lt;title&gt;Login&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;\n&lt;h2&gt;Login&lt;\/h2&gt;\n&lt;form method=\"post\"&gt;\n    Username: &lt;input type=\"text\" name=\"username\" required&gt;&lt;br&gt;\n    Password: &lt;input type=\"password\" name=\"password\" required&gt;&lt;br&gt;\n    &lt;button type=\"submit\"&gt;Login&lt;\/button&gt;\n&lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: OTP Verification<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ verify.php\nrequire 'vendor\/autoload.php';\nuse Sonata\\GoogleAuthenticator\\GoogleAuthenticator;\nsession_start();\n\nif (!isset($_SESSION&#91;'pending_user'])) {\n    header(\"Location: login.php\");\n    exit;\n}\n\n$user = $_SESSION&#91;'pending_user'];\n$g = new GoogleAuthenticator();\n\nif ($_SERVER&#91;'REQUEST_METHOD'] === 'POST') {\n    $code = $_POST&#91;'otp_code'];\n    if ($g-&gt;checkCode($user&#91;'secret'], $code)) {\n        $_SESSION&#91;'authenticated'] = true;\n        $_SESSION&#91;'username'] = $user&#91;'username'];\n        unset($_SESSION&#91;'pending_user']);\n        header(\"Location: dashboard.php\");\n        exit;\n    } else {\n        echo \"\u274c Invalid OTP, try again.\";\n    }\n}\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;&lt;title&gt;Verify OTP&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;\n&lt;h2&gt;Enter 6-digit code from Google Authenticator&lt;\/h2&gt;\n&lt;form method=\"post\"&gt;\n    &lt;input type=\"text\" name=\"otp_code\" required maxlength=\"6\"&gt;&lt;br&gt;\n    &lt;button type=\"submit\"&gt;Verify&lt;\/button&gt;\n&lt;\/form&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Dashboard Page (Protected)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ dashboard.php\nsession_start();\nif (!isset($_SESSION&#91;'authenticated'])) {\n    header(\"Location: login.php\");\n    exit;\n}\n?&gt;\n&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;&lt;title&gt;Dashboard&lt;\/title&gt;&lt;\/head&gt;\n&lt;body&gt;\n&lt;h2&gt;Welcome, &lt;?= htmlspecialchars($_SESSION&#91;'username']) ?&gt; \ud83c\udf89&lt;\/h2&gt;\n&lt;p&gt;You are logged in with 2FA enabled!&lt;\/p&gt;\n&lt;a href=\"logout.php\"&gt;Logout&lt;\/a&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 7: Logout<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ logout.php\nsession_start();\nsession_destroy();\nheader(\"Location: login.php\");\nexit;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Security Best Practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use HTTPS in production.<\/li>\n\n\n\n<li>Store passwords with <code>password_hash()<\/code> and <code>password_verify()<\/code>.<\/li>\n\n\n\n<li>Protect against brute-force by limiting login attempts.<\/li>\n\n\n\n<li>Provide backup codes or an option to disable 2FA via email verification in case the user loses their phone.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Conclusion<\/h2>\n\n\n\n<p>We built a complete <strong>Google Authenticator 2FA login system in PHP<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>User registers \u2192 gets QR code.<\/li>\n\n\n\n<li>User logs in \u2192 enters username &amp; password.<\/li>\n\n\n\n<li>User enters OTP from Google Authenticator.<\/li>\n\n\n\n<li>If correct, access is granted.<\/li>\n<\/ol>\n\n\n\n<p>This simple setup greatly improves account security and can be integrated into any existing PHP application.<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-100\"><a class=\"wp-block-button__link has-vivid-green-cyan-background-color has-background wp-element-button\" href=\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/2fa-php-login.zip\">Download ZIP<\/a><\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Passwords alone aren\u2019t enough to keep your application secure. Attackers often crack or steal credentials, which is why Two-Factor Authentication (2FA) has become standard in modern applications. In this tutorial, we\u2019ll build a PHP login system with Google Authenticator that requires both a password and a one-time code from the user\u2019s phone. Prerequisites Step 1: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2120,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"googlesitekit_rrm_CAow44u0DA:productID":"","footnotes":""},"categories":[5],"tags":[9],"class_list":["post-2118","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-web-development"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Implement Google Authenticator 2FA Login in PHP - Itxperts<\/title>\n<meta name=\"description\" content=\"Learn how to add Two-Factor Authentication (2FA) in PHP using Google Authenticator. This step-by-step guide covers registration, QR code generation, OTP verification, and a complete working PHP login system with source code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Implement Google Authenticator 2FA Login in PHP - Itxperts\" \/>\n<meta property=\"og:description\" content=\"Learn how to add Two-Factor Authentication (2FA) in PHP using Google Authenticator. This step-by-step guide covers registration, QR code generation, OTP verification, and a complete working PHP login system with source code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Itxperts\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/itxperts.co.in\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-24T12:18:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-11T07:17:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator-1024x683.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"683\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"@mritxperts\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"@mritxperts\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\"},\"author\":{\"name\":\"@mritxperts\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/#\/schema\/person\/77ad4d47f9f82583ee23e37010a52fc6\"},\"headline\":\"How to Implement Google Authenticator 2FA Login in PHP\",\"datePublished\":\"2025-09-24T12:18:52+00:00\",\"dateModified\":\"2026-01-11T07:17:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\"},\"wordCount\":244,\"publisher\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png\",\"keywords\":[\"web development\"],\"articleSection\":[\"Web Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\",\"url\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\",\"name\":\"How to Implement Google Authenticator 2FA Login in PHP - Itxperts\",\"isPartOf\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png\",\"datePublished\":\"2025-09-24T12:18:52+00:00\",\"dateModified\":\"2026-01-11T07:17:18+00:00\",\"description\":\"Learn how to add Two-Factor Authentication (2FA) in PHP using Google Authenticator. This step-by-step guide covers registration, QR code generation, OTP verification, and a complete working PHP login system with source code.\",\"breadcrumb\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage\",\"url\":\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png\",\"contentUrl\":\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png\",\"width\":1536,\"height\":1024,\"caption\":\"Google Authenticator PHP PHP 2FA Login Two Factor Authentication in PHP Google Authenticator OTP PHP Secure PHP Login with 2FA PHP Login System with Google Authenticator\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/itxperts.co.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Implement Google Authenticator 2FA Login in PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/#website\",\"url\":\"https:\/\/itxperts.co.in\/blog\/\",\"name\":\"Itxperts\",\"description\":\"Leading Website Design Company in Madhya Pradesh\",\"publisher\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/#organization\"},\"alternateName\":\"Itxperts | Website Development in Madhya Pradesh\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/itxperts.co.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/#organization\",\"name\":\"Itxperts\",\"alternateName\":\"Leading Website Design Company in Madhya Pradesh \u2013 Itxperts\",\"url\":\"https:\/\/itxperts.co.in\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/05\/cropped-itxperts_logo.png\",\"contentUrl\":\"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/05\/cropped-itxperts_logo.png\",\"width\":512,\"height\":512,\"caption\":\"Itxperts\"},\"image\":{\"@id\":\"https:\/\/itxperts.co.in\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/itxperts.co.in\",\"https:\/\/www.linkedin.com\/company\/itxpertsshivpuri\/\",\"https:\/\/www.instagram.com\/itxperts.co.in\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/#\/schema\/person\/77ad4d47f9f82583ee23e37010a52fc6\",\"name\":\"@mritxperts\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/itxperts.co.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/702cffafd84d85872c0d42d33a9fa39140418d7c60a1311a1f8f55b005d0570b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/702cffafd84d85872c0d42d33a9fa39140418d7c60a1311a1f8f55b005d0570b?s=96&d=mm&r=g\",\"caption\":\"@mritxperts\"},\"description\":\"I am a full-stack web developer from India with over 8 years of experience in building dynamic and responsive web solutions. Specializing in both front-end and back-end development, I have a passion for creating seamless digital experiences. When I'm not coding, I enjoy sharing insights and tutorials on the latest web technologies, helping fellow developers stay ahead in the ever-evolving tech landscape.\",\"sameAs\":[\"https:\/\/itxperts.co.in\/blog\"],\"url\":\"https:\/\/itxperts.co.in\/blog\/author\/mritxpertsgmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Implement Google Authenticator 2FA Login in PHP - Itxperts","description":"Learn how to add Two-Factor Authentication (2FA) in PHP using Google Authenticator. This step-by-step guide covers registration, QR code generation, OTP verification, and a complete working PHP login system with source code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/","og_locale":"en_US","og_type":"article","og_title":"How to Implement Google Authenticator 2FA Login in PHP - Itxperts","og_description":"Learn how to add Two-Factor Authentication (2FA) in PHP using Google Authenticator. This step-by-step guide covers registration, QR code generation, OTP verification, and a complete working PHP login system with source code.","og_url":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/","og_site_name":"Itxperts","article_publisher":"https:\/\/www.facebook.com\/itxperts.co.in","article_published_time":"2025-09-24T12:18:52+00:00","article_modified_time":"2026-01-11T07:17:18+00:00","og_image":[{"width":1024,"height":683,"url":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator-1024x683.png","type":"image\/png"}],"author":"@mritxperts","twitter_card":"summary_large_image","twitter_misc":{"Written by":"@mritxperts","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#article","isPartOf":{"@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/"},"author":{"name":"@mritxperts","@id":"https:\/\/itxperts.co.in\/blog\/#\/schema\/person\/77ad4d47f9f82583ee23e37010a52fc6"},"headline":"How to Implement Google Authenticator 2FA Login in PHP","datePublished":"2025-09-24T12:18:52+00:00","dateModified":"2026-01-11T07:17:18+00:00","mainEntityOfPage":{"@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/"},"wordCount":244,"publisher":{"@id":"https:\/\/itxperts.co.in\/blog\/#organization"},"image":{"@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage"},"thumbnailUrl":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png","keywords":["web development"],"articleSection":["Web Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/","url":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/","name":"How to Implement Google Authenticator 2FA Login in PHP - Itxperts","isPartOf":{"@id":"https:\/\/itxperts.co.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage"},"image":{"@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage"},"thumbnailUrl":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png","datePublished":"2025-09-24T12:18:52+00:00","dateModified":"2026-01-11T07:17:18+00:00","description":"Learn how to add Two-Factor Authentication (2FA) in PHP using Google Authenticator. This step-by-step guide covers registration, QR code generation, OTP verification, and a complete working PHP login system with source code.","breadcrumb":{"@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#primaryimage","url":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png","contentUrl":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/09\/Google-Authenticator-PHP-PHP-2FA-Login-Two-Factor-Authentication-in-PHP-Google-Authenticator-OTP-PHP-Secure-PHP-Login-with-2FA-PHP-Login-System-with-Google-Authenticator.png","width":1536,"height":1024,"caption":"Google Authenticator PHP PHP 2FA Login Two Factor Authentication in PHP Google Authenticator OTP PHP Secure PHP Login with 2FA PHP Login System with Google Authenticator"},{"@type":"BreadcrumbList","@id":"https:\/\/itxperts.co.in\/blog\/google-authenticator-2fa-login-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itxperts.co.in\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Implement Google Authenticator 2FA Login in PHP"}]},{"@type":"WebSite","@id":"https:\/\/itxperts.co.in\/blog\/#website","url":"https:\/\/itxperts.co.in\/blog\/","name":"Itxperts","description":"Leading Website Design Company in Madhya Pradesh","publisher":{"@id":"https:\/\/itxperts.co.in\/blog\/#organization"},"alternateName":"Itxperts | Website Development in Madhya Pradesh","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itxperts.co.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/itxperts.co.in\/blog\/#organization","name":"Itxperts","alternateName":"Leading Website Design Company in Madhya Pradesh \u2013 Itxperts","url":"https:\/\/itxperts.co.in\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itxperts.co.in\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/05\/cropped-itxperts_logo.png","contentUrl":"https:\/\/itxperts.co.in\/blog\/wp-content\/uploads\/2025\/05\/cropped-itxperts_logo.png","width":512,"height":512,"caption":"Itxperts"},"image":{"@id":"https:\/\/itxperts.co.in\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/itxperts.co.in","https:\/\/www.linkedin.com\/company\/itxpertsshivpuri\/","https:\/\/www.instagram.com\/itxperts.co.in\/"]},{"@type":"Person","@id":"https:\/\/itxperts.co.in\/blog\/#\/schema\/person\/77ad4d47f9f82583ee23e37010a52fc6","name":"@mritxperts","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itxperts.co.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/702cffafd84d85872c0d42d33a9fa39140418d7c60a1311a1f8f55b005d0570b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/702cffafd84d85872c0d42d33a9fa39140418d7c60a1311a1f8f55b005d0570b?s=96&d=mm&r=g","caption":"@mritxperts"},"description":"I am a full-stack web developer from India with over 8 years of experience in building dynamic and responsive web solutions. Specializing in both front-end and back-end development, I have a passion for creating seamless digital experiences. When I'm not coding, I enjoy sharing insights and tutorials on the latest web technologies, helping fellow developers stay ahead in the ever-evolving tech landscape.","sameAs":["https:\/\/itxperts.co.in\/blog"],"url":"https:\/\/itxperts.co.in\/blog\/author\/mritxpertsgmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/posts\/2118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/comments?post=2118"}],"version-history":[{"count":1,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/posts\/2118\/revisions"}],"predecessor-version":[{"id":2121,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/posts\/2118\/revisions\/2121"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/media\/2120"}],"wp:attachment":[{"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/media?parent=2118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/categories?post=2118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itxperts.co.in\/blog\/wp-json\/wp\/v2\/tags?post=2118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}