vincent15000's avatar

Authentication with password vs 2FA

Hello,

When reading some documentation and recommendations about security and authentication (in France we have the CNIL for that), if an application handles sensitive datas (according to GDPR), it's recommended to have :

  • either a password with entropy 80 or greater : uppercase, lowercase, numbers, special characters and minimum 14 characters long

  • or 2FA, then the password can be less strong

What about your choices ?

A lot of users don't want 2FA because it's restrictive, they need to receive a code and then type the code ... it's not so pratice.

So is it really better to have 2FA than a very strong password ? Or are both similar to protect access to an application ?

Thanks for sharing your experience with different kings of authentication processes ;).

V

0 likes
6 replies
LaryAI's avatar
Level 58

Certainly! Here is a thoughtful solution to the Laracasts forum question regarding password strength vs. 2FA, along with some code advice where applicable.


Great question! This comes up a lot in application security, and there are pros and cons to both approaches. Here’s a breakdown:

Strong Passwords

Pros:

  • Simple for users who can remember complex passwords (though most users don't).
  • Single-step authentication (convenient).

Cons:

  • Users often reuse strong passwords across sites.
  • Even a strong password can be leaked through phishing or malware.
  • Usability: users hate creating/remembering long, complex passwords.

2FA (Two-Factor Authentication)

Pros:

  • Even if the password is compromised, the account is protected via the second factor.
  • The extra protection is significant, especially for sensitive data.
  • Most security breaches in recent years exploited password-only authentication.

Cons:

  • Added friction to the user experience.
  • Dependence on users having their phone/device/secure email.

Which is "better"?

Best practice: Use strong passwords and 2FA whenever possible.
If you must choose only one and your threat model is focused on user convenience, a decent password (10+ chars, some complexity) with 2FA usually provides comparable or better protection than a single ultra-strong password.

Most organizations quickly move towards 2FA for anything sensitive because passwords alone—even strong ones—can be phished, reused, or stolen in plaintext/leaks.

Minimum Recommendation (CNIL, GDPR, & general security guidelines):

  • For sensitive data: Strong password AND 2FA.
  • Without 2FA: Require extremely strong passwords (as you described) and recommend regular changes.

What do I do in my apps?

Most apps go with password of reasonable strength + optional/enforced 2FA for sensitive actions.

In Laravel, you can enable 2FA easily with packages like Laravel Fortify, or roll your own.

Sample 2FA prompt using Fortify:

// In your LoginController or equivalent
public function authenticate(Request $request)
{
    $credentials = $request->only('email', 'password');

    if (Auth::attempt($credentials)) {
        if (Auth::user()->two_factor_enabled) {
            // Show 2FA code input (handled via Fortify)
        }
        // Log user in
    } else {
        // Return error
    }
}

Enforcing strong password validation using Laravel validation:

$request->validate([
    'password' => [
        'required',
        'string',
        'min:14', // minimum 14 chars
        'regex:/[a-z]/',      // lowercase
        'regex:/[A-Z]/',      // uppercase
        'regex:/[0-9]/',      // number
        'regex:/[@$!%*#?&]/', // special char
    ],
]);

Conclusion / TL;DR

  • 2FA provides a huge security boost.
  • Strong passwords are essential, but not enough against phishing/leaks.
  • Combine both for sensitive data if you can.
  • If users refuse 2FA, require very strong passwords and educate them about secure practices.

User experience is always a balance—give 2FA as an option and gently push users towards it with education and incentives (e.g., warn about extra-sensitive actions).


Community input on your settings and user feedback is always valuable!
Hope this helps clarify the tradeoffs! 🚀


Snapey's avatar

password only can be captured and replayed in attacks at a later date. Most 2FA solutions are time sensitive, so even if someone is watching you type, they cant know what the code might be in the future.

People have their favourite passwords, so a compromise on one system can lead to other break-ins.

Password only is vulnerable to password reset tactics. If a bad guy can intercept or eavesdrop on your email, they can attempt password reset. Not so with 2fa

1 like
vincent15000's avatar

Ok so it's primarily in case of password theft.

I think about another case : so why not use only a code with OTP and no password ?

Does OTP generate codes according to the device ? I mean if I install the 2FA application on 2 different smartphones, does i't generale the same code at exactly the same time ?

Snapey's avatar

If you are thinking about the Google authenticator type device, then yes, two devices initialised from the same account will give the same pattern. Its nothing to do with the device itself.

The account provides the seed to the sequence.

1 like
vincent15000's avatar

Yes I thought about the FreeOTP application.

That means that a person can access to the code generated by the OTP application no ?

I mean ... ok the code that is generated depends on the account, but if a person knows theses informations about the account, he can also generate the right code ?

So if I know the password and informations about the account, there is a real possibility to generate the right code to access the application via 2FA ?

UPDATE => In fact OTP generates a secret key shared with the device when 2FA is activated via the QR-code. Does this key depend on the account ? I don't know.

Snapey's avatar
Snapey
Best Answer
Level 122

Fortify generates a unique code for the user, and this is stored in the users table under two_factor_secret. This is then used to create the QR code to initialise the Time based One Time Password generator (TOTP).

As long as the secret stays secret (on the server) then if should not be possible to generate another TOTP.

1 like

Please or to participate in this conversation.