PHPackages                             doge-dev/laravel-google-authenticator - 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. doge-dev/laravel-google-authenticator

ActiveLibrary

doge-dev/laravel-google-authenticator
=====================================

Google Authenticator implementation for Laravel

1.0.1(7y ago)01.5kMITPHP

Since Jun 19Pushed 7y ago1 watchersCompare

[ Source](https://github.com/doge-dev/laravel-google-authenticator)[ Packagist](https://packagist.org/packages/doge-dev/laravel-google-authenticator)[ RSS](/packages/doge-dev-laravel-google-authenticator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

laravel-google-authenticator
============================

[](#laravel-google-authenticator)

Google Authenticator implementation for Laravel

The package has a trait and a custom validation rule that you can use on any model for verifying the Google Authenticators code.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Example](#example)
- [Displaying the QR code](#displaying-the-qr-code)
- [Verifying that the User set up Google Authenticator](#verifying-that-the-user-set-up-google-authenticator)
- [Adding 2FA custom Validation](#adding-2fa-custom-validation)
- [Adding 2FA custom Validation using route model binding](#adding-2fa-custom-validation-using-route-model-binding)
- [Adding a custom name in Google Authenticator](#adding-a-custom-name-in-google-authenticator)

Installation
------------

[](#installation)

Pull the lib with composer:

```
composer require doge-dev/laravel-google-authenticator
```

Add the service provider in `config/app.php`

```
DogeDev\GoogleAuthenticator\GoogleAuthenticatorServiceProvider::class,
```

You can add 2 Factor Verification to any model, and it will create:

- A getter (accessor) for **enabled\_2fa** attribute
- function **enable2FA()** - enables 2 Factor Authentication on the model.
- function **getQRCodeURL()** - gets the URL for retrieving the QR code image for the User to scan with Google Authenticator
- function **getBase64EncodedQRImage()** - gets the base64 encoded image (convenient for placing into [![](...)](...) for emails and such...)
- function **verifyCode($code)** - attempts to verify the code submitted by the user (will increment the attempts)
- function **activate2FA($code)** - attempts to verify the code and on successful verification will set the `activated_2fa` attribute to true
- function **getNameForQRCode()** - function that is used for generating a name that will be displayed in the Google Authenticator App (you can overwrite this function to use a custom naming convention)

Example
-------

[](#example)

Add the `Verifies2FACode` trait to your User model (or any other model on which you might want to enable 2FA):

```
