Laravel two-factor authentication

Two-factor authentication in Laravel

Two-factor authentication offers a way to add extra protection layer for your website’s user accounts. This allows your users to protect their accounts from unauthorized access. There are many providers that offers such services. In this post, we will use Authy. Authy provides a very robust API for implementing two-factor authentication. You can find API documentation for Authy here.

First you must install composer & create a new laravel application.


  • Use following command to install:

  • Add following to $providers array in config/app.php:

  • Add following to $aliases array in config/app.php:

  • Publish configuration:

  • Migrate user table changes to database:

  • Add the following lines to User model (e.g App\User.php)
    • Before the class declaration, add these lines:

  • Now the change the class declaration. For example, if your class declaration is

to this:

  • Now change the import traits line accordingly in user model file. For example if the line is:


  • Lastly, add/update $hidden variable to hide ‘two_factor_options’ field from any DB call for user detail:


You can view further documentation for this plugin here.

I have also implemented it in a sample laravel application as well. You can view installation instructions here. Through this application, you can do:

  • User login & registration.
  • Enable/Disable two-factor authentication for a user.

Following are the download links for the laravel demo application with two-factor authentication:

  • Ed Greenberg

    Any chance of this for 5.3?

  • Jeet Jaiswal

    for laravel 5.3 its not working for me i have also download 5.3 demo its also not working for me .
    on my localhost

    the login form have no validation field please suggest