DhPandya's avatar

Laracasts 2FA

Hello @JeffreyWay

First of all, thank you very much for the high-quality content Laracasts provides.

Today, I was just walking through the profile section and noticed that Laracasts didn't have 2FA. What are your thoughts on it?

Are you adding it by near time?

Regards,

0 likes
5 replies
LaryAI's avatar
Level 58

Thanks for your thoughtful question!

While I'm not able to comment on Laracasts' roadmap or future features, I can share some advice regarding implementing Two-Factor Authentication (2FA) in a Laravel application (the framework Laracasts is based on).

If you're interested in adding 2FA to your own Laravel projects, here's a quick overview of how you can do it using the excellent Laravel Fortify package, which supports two-factor authentication out of the box.

Step 1: Install Fortify

composer require laravel/fortify

Step 2: Publish Fortify's resources

php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"

Step 3: Enable Two-Factor Authentication in config/fortify.php

'features' => [
    // ...
    Features::twoFactorAuthentication([
        'confirmPassword' => true,
    ]),
],

Step 4: Add the two-factor authentication scaffolding to your frontend.
Fortify registers the necessary routes (such as enabling/disabling 2FA and QR code generation). You can provide a UI for enabling 2FA, showing the QR code, and entering recovery codes.

See the Fortify documentation here for full details:
https://laravel.com/docs/10.x/fortify#two-factor-authentication

Simple Example: Enabling 2FA for a user

In your profile settings blade template:

@if (!auth()->user()->two_factor_secret)
    <form method="POST" action="{{ url('/user/two-factor-authentication') }}">
        @csrf
        <button type="submit">Enable Two-Factor Authentication</button>
    </form>
@else
    <form method="POST" action="{{ url('/user/two-factor-authentication') }}">
        @csrf
        @method('DELETE')
        <button type="submit">Disable Two-Factor Authentication</button>
    </form>
@endif

Conclusion
2FA dramatically increases account security. Whether or not Laracasts itself adds it soon, you can implement it in your own apps quite easily using Laravel's tools!

Let me know if you need an example using a package other than Fortify.

jlrdw's avatar

It's a forum, so really 2FA isn't needed. If an account like a bank then I can see deeper security. Just my opinion.

DhPandya's avatar

I'm thinking about the accounts that have a premium plan. 2FA will add an extra security layer.

jlrdw's avatar

What's funny and just an example, is Google sends an code to a yahoo mail account to verify meanwhile yahoo sends one to google, suddenly you can't access either due to 2FA.

The only 2FA I like is the code sent on mobile.

Some of the 2FA gets out of hand.

Here on Laracasts, I would in your case always log out and have a strong password.

Just a suggestion.

1 like

Please or to participate in this conversation.