Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jonaspas's avatar

2 Factor Authentication with email

Hi there,

I want to implement a two factor authentication into my Laravel app. I want that the person, after entering username and password, get's an email with a link which he has to click to get logged in into the system.

I see, that there a several packages for 2 factor auth (e.g. https://github.com/srmklive/laravel-twofactor-authentication, https://github.com/antonioribeiro/google2fa), but none of them has the option to authenticate via email out of the box. Only SMS, phone call oder One time password seems to be supported.

Is two factor auth by email a bad practice or considered unsecure for some reason? Or is it so simple to implement manually, that there are no packages for that?

Thanks in advance! Jonas

0 likes
5 replies
wilburpowery's avatar
Level 23

I don't think it's a bad practice. But I don't really see the value of it. To keep it simple, you can just add a column to your user's table like login_token or something similar, and create a random string token when the user hits the LoginController method. You would have to override a method in one of the traits to avoid Laravel from logging the user in. Use the mail facade to send an email to the user. You can create an endpoint like: /users/login/{token} where it hits a TokenLoginController and you search for a User with that login token, and manually log them in.

Hope it helps!

2 likes
tokoiwesley's avatar

I don't think it's a bad practice because it qualifies as a two-step verification process where on sign in, a user will enter their password as usual and then they'll be asked for something else to confirm their claimed identity. However, '

I also think it's simple enough to implement manually - thus no need for a package. However, from a multi-factor authentication - https://en.wikipedia.org/wiki/Multi-factor_authentication - perspective it will have little value. I suggest that you consider including the recommendation by @wilburpowery in your implementation to add a concept of tokenization - https://en.wikipedia.org/wiki/Tokenization_(data_security).

2 likes
jonaspas's avatar

Hey, thank you for your evaluation of my situation, the links and the hints! Yeah, I guess I have to read about the basics of multi factor auth a little bit more and probably then I will try to implement the logic described by @wilburpowery. Thank you both very much, this really helps me! :)

Please or to participate in this conversation.