PHPackages                             pragmarx/google2fa-qrcode - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. pragmarx/google2fa-qrcode

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

pragmarx/google2fa-qrcode
=========================

QR Code package for Google2FA

v3.0.1(8mo ago)12124.6M—3.8%2820MITPHPPHP &gt;=7.1CI passing

Since Oct 7Pushed 1w ago3 watchersCompare

[ Source](https://github.com/antonioribeiro/google2fa-qrcode)[ Packagist](https://packagist.org/packages/pragmarx/google2fa-qrcode)[ RSS](/packages/pragmarx-google2fa-qrcode/feed)WikiDiscussions 4.x Synced 1mo ago

READMEChangelogDependencies (5)Versions (10)Used By (20)

Google2FA QRCode
================

[](#google2fa-qrcode)

 [![Latest Stable Version](https://camo.githubusercontent.com/6a06d83ef5479dd9ca58842854e969fbad623bf177997b993e01540ddc1349b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f707261676d6172782f676f6f676c653266612d7172636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pragmarx/google2fa-qrcode) [![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md) [![PHPUnit](https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpunit.yml/badge.svg)](https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpunit.yml) [![PHPStan](https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpstan.yml/badge.svg)](https://github.com/antonioribeiro/google2fa-qrcode/actions/workflows/phpstan.yml)

 [![Downloads](https://camo.githubusercontent.com/a61d37742117af7da4e561e17baed8e12a41f7e77e4b3ed815e6093a6424d2b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f707261676d6172782f676f6f676c653266612d7172636f64652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pragmarx/google2fa-qrcode) [![Coverage](https://camo.githubusercontent.com/9077f9cecf19af5b33314fd16720f96c084f3a4824b95052ba7d66b50e22376c/68747470733a2f2f636f6465636f762e696f2f67682f616e746f6e696f7269626569726f2f676f6f676c653266612d7172636f64652f6272616e63682f342e782f67726170682f62616467652e737667)](https://codecov.io/gh/antonioribeiro/google2fa-qrcode) [![PHP](https://camo.githubusercontent.com/db7cdd884a5671405965c5a91d3ea8f10381e06458d7c9f5aa9b55cf2387704a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532302d2d253230382e352d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://www.php.net)

### QRCode For Google2FA

[](#qrcode-for-google2fa)

This is package is [Goole2FA](https://github.com/antonioribeiro/google2fa) integrated with a QRCode generator, providing an easy way to plot QRCode for your two factor authentication. For documentation related to Google2FA, please check the [documentation of the main package](https://github.com/antonioribeiro/google2fa).

Version Compatibility
---------------------

[](#version-compatibility)

PHP`pragmarx/google2fa-qrcode``7.1``3.x``7.2``3.x``7.3``3.x``7.4``3.x``8.0``3.x``8.1``4.x``8.2``4.x``8.3``4.x``8.4``4.x``8.5``4.x`Installing
----------

[](#installing)

Use Composer to install it:

```
composer require pragmarx/google2fa-qrcode

```

Using It
--------

[](#using-it)

### Instantiate it directly

[](#instantiate-it-directly)

```
use PragmaRX\Google2FAQRCode\Google2FA;

$google2fa = new Google2FA();

return $google2fa->generateSecretKey();
```

Generating QRCodes
------------------

[](#generating-qrcodes)

The securer way of creating QRCode is to do it yourself or using a library. First you have to install the Chillerlan or BaconQrCode package, then you just have to generate the inline string using:

```
$inlineUrl = $google2fa->getQRCodeInline(
    $companyName,
    $companyEmail,
    $secretKey
);
```

And use it in your blade template this way:

```

```

```
$secretKey = $google2fa->generateSecretKey(16, $userId);
```

Show the QR Code to your user, via Google Apis
----------------------------------------------

[](#show-the-qr-code-to-your-user-via-google-apis)

It's insecure to use it via Google Apis, so you have to enable it before using it.

```
$google2fa->setAllowInsecureCallToGoogleApis(true);

$google2fa_url = $google2fa->getQRCodeGoogleUrl(
    'YourCompany',
    $user->email,
    $user->google2fa_secret
);

/// and in your view:

```

And they should see and scan the QR code to their applications:

[![QRCode](https://camo.githubusercontent.com/b452d09f2effb9718266d946358d3971141f825635da0c4383a6784d8f93463c/68747470733a2f2f63686172742e676f6f676c65617069732e636f6d2f63686172743f6368733d323030783230302663686c643d4d25374330266368743d71722663686c3d6f747061757468253341253246253246746f7470253246507261676d615258253341616372253242707261676d617278253430616e746f6e696f6361726c6f737269626569726f2e636f6d2533467365637265742533444144554d4a4f353633344e5044454b57253236697373756572253344507261676d615258)](https://camo.githubusercontent.com/b452d09f2effb9718266d946358d3971141f825635da0c4383a6784d8f93463c/68747470733a2f2f63686172742e676f6f676c65617069732e636f6d2f63686172743f6368733d323030783230302663686c643d4d25374330266368743d71722663686c3d6f747061757468253341253246253246746f7470253246507261676d615258253341616372253242707261676d617278253430616e746f6e696f6361726c6f737269626569726f2e636f6d2533467365637265742533444144554d4a4f353633344e5044454b57253236697373756572253344507261676d615258)

And to verify, you just have to:

```
$secret = $request->input('secret');

$valid = $google2fa->verifyKey($user->google2fa_secret, $secret);
```

Replacing the QRCode rendering service
--------------------------------------

[](#replacing-the-qrcode-rendering-service)

If you want to use a different service, you just have to

```
$google2fa->setQRCodeService(new YourService())
          ->getQRCodeInline(
              $companyName,
              $companyEmail,
              $secretKey
          );
```

Built-in QRCode rendering services
----------------------------------

[](#built-in-qrcode-rendering-services)

Beginning on version 2.0 the rendering service is optional, so you have to manually install one of those packages in order to generate QRCodes:

- [BaconQrCode](https://github.com/Bacon/BaconQrCode): renders PNG by default, but requires the Imagick PHP extension. You can configure it to use different backends, but you'll have to instantiate it yourself.
- [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode): renders SVG by default and don't require the Imagick PHP extension, but can also generate other formats, which may require Imagick.

Using a different image backend
-------------------------------

[](#using-a-different-image-backend)

```
$google2fa->setQRCodeService(
    new \PragmaRX\Google2FAQRCode\QRCode\Bacon(
        new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
    )
);

// or

$google2fa = new Google2FA(
    new Bacon(
        new \BaconQrCode\Renderer\Image\SvgImageBackEnd()
    )
);
```

Tests
-----

[](#tests)

The package tests were written with [PHPUnit](https://phpunit.de/).

Authors
-------

[](#authors)

- [Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)
- [All Contributors](https://github.com/antonioribeiro/google2fa/graphs/contributors)

License
-------

[](#license)

Google2FAQRCode is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

Contributing
------------

[](#contributing)

Pull requests and issues are more than welcome.

###  Health Score

64

↑

FairBetter than 99% of packages

Maintenance82

Actively maintained with recent releases

Popularity66

Solid adoption and visibility

Community34

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 86.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~317 days

Recently: every ~449 days

Total

9

Last Release

241d ago

Major Versions

v1.0.3 → v2.0.02020-10-16

v2.1.1 → v3.0.02021-08-15

PHP version history (2 changes)v1.0.0PHP &gt;=5.4

v2.0.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d9421a69d192db597169ec3519ad3efc6a35a660e4525e2ed08f6c753b908e86?d=identicon)[AntonioCarlosRibeiro](/maintainers/AntonioCarlosRibeiro)

---

Top Contributors

[![antonioribeiro](https://avatars.githubusercontent.com/u/3182864?v=4)](https://github.com/antonioribeiro "antonioribeiro (59 commits)")[![sergejostir](https://avatars.githubusercontent.com/u/21297285?v=4)](https://github.com/sergejostir "sergejostir (2 commits)")[![jangidgirish](https://avatars.githubusercontent.com/u/4018017?v=4)](https://github.com/jangidgirish "jangidgirish (1 commits)")[![KartaviK](https://avatars.githubusercontent.com/u/5941637?v=4)](https://github.com/KartaviK "KartaviK (1 commits)")[![MauricioFauth](https://avatars.githubusercontent.com/u/120970?v=4)](https://github.com/MauricioFauth "MauricioFauth (1 commits)")[![mrtus](https://avatars.githubusercontent.com/u/8998239?v=4)](https://github.com/mrtus "mrtus (1 commits)")[![phit](https://avatars.githubusercontent.com/u/2097483?v=4)](https://github.com/phit "phit (1 commits)")[![williamdes](https://avatars.githubusercontent.com/u/7784660?v=4)](https://github.com/williamdes "williamdes (1 commits)")[![eusonlito](https://avatars.githubusercontent.com/u/644551?v=4)](https://github.com/eusonlito "eusonlito (1 commits)")

---

Tags

qr codeqrcodeAuthentication2faTwo Factor Authenticationgoogle2fa

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pragmarx-google2fa-qrcode/health.svg)

```
[![Health](https://phpackages.com/badges/pragmarx-google2fa-qrcode/health.svg)](https://phpackages.com/packages/pragmarx-google2fa-qrcode)
```

###  Alternatives

[pragmarx/google2fa

A One Time Password Authentication package, compatible with Google Authenticator.

2.0k82.4M164](/packages/pragmarx-google2fa)[pragmarx/google2fa-laravel

A One Time Password Authentication package, compatible with Google Authenticator.

1.0k15.5M63](/packages/pragmarx-google2fa-laravel)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[stephenjude/filament-two-factor-authentication

Filament Two Factor Authentication: Google 2FA + Passkey Authentication

81158.7k4](/packages/stephenjude-filament-two-factor-authentication)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2010.2k](/packages/remotemerge-totp-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
