Laravel 8 Two Factor Authentication using Laravel Jetstream.

Laravel 8 Two Factor Authentication using Laravel Jetstream.

ยท

2 min read

Table of contents

  1. Create new Laravel project
  2. Configure Database Credentials
  3. Install Laravel Jetstream
  4. Configure Two Factor Authentication
  5. GitHub Repo

1. Create new project.

In your terminal execute

composer create-project laravel/laravel Two-Factor-Authentication

2. Configure Database Credentials.

Open your .env file and edit your credentials like this

# Database Credentials
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

3. Install Laravel Jetstream

To install Laravel Jetstream execute this command in your terminal

composer require laravel/jetstream

After installing the package, run this command

php artisan jetstream:install livewire

To finish this part you need to run

npm install && npm run dev

Note: You need to have installed node.js to execute npm install && npm run dev

Finally we need to run our migrations.

php artisan migrate

Now we can see the registration and login page.

Registration

register.png

Login login.png

Let's move to the next step.

4. Configure Two Factor Authentication

We need to register a new user

new_register.png

In your dashboard search for Profile located in the right-hand side menu.

menu.png

Let's go to Two Factor Authentication

two-factor.png

Click Enable Button and you need to confirm your password to continue

confirm-password.png

When you confirm the password you'll see something like that

enabled_two_factor.png

You need to scan the QR code with a mobile application like Google Authenticator, Authy. If you want to check more apps you can see this link Top 10 Best Authenticator Apps

When you finish this step try to login again and you'll see code.png

Put the code and that's it. Everything is ready and working.

Note:

  • Remember to store in a safe place the RECOVERY CODES in case you lose your phone.
  • You can enable and disable the Two Factor Authentication every time you want

5. GitHub Repo

Link: Two Factor Authentication

If you have any doubt leave a message in the comment section.

Happy coding โ˜•. Thanks for reading ๐Ÿ™

ย