Email 2 step authentication (2fa) implementation - looking for feedback

Hello,

I am embarking on a quest to build a two step email authentication for my web app (there are good reasons not to use Google Authenticator).

I’m nearly there but I’d like to humbly ask the community for feedback on how to improve. I am not saying this is the right way, but’s how I’ve gotten it to work. So if you have any ideas on how to improve/make more secure, I’m all ears!

The idea is that a user inputs their credentials here:
image

Then, they get an email with an auth code to input here:
image

A few notes:

On the login page the logic is as follows:

  1. Query to get login attempts for posted email
  2. Then, increment this number by 1
  3. If the count is less than 10, proceed to the first security provider and attempt to log in
  4. After login, set the 2fa token value, expiration date/time and update the DB
  5. Query the DB to get the user’s first name and send user an email with 2fa auth code

If login attempts > 10, send a 403 to the front end with a pretty error message and eventually email the user to let them know what happened to their account.

On the ‘enter auth code page’ the logic is as follows:

  1. To access this page, the user should have successfully logged into the prior page
  2. Query the user for posted email to get the 2fa expiration time and token value
  3. Update the number of login attempts
  4. If date/time is less than 15 minutes AND login count < 10, go to THEN condition
  5. Try to log the user in with the posted auth token
  6. Then reset the expiration time, token and login attempts

If the login count > 10, respond with a 403 status.

I’d love to get feedback and suggestions on how to improve.

Community Page
Last updated: