How to disable login after multiple failed attempts in Flutter

Viewed 656

I have built a flutter app where user is created at backend WEB, in App users can only Login. What I want to do is if the user attempts multiple failed attempt to login assume for 3 times, I want Login to get disabled for 5 minutes to the user.

help me how to approach it and the best suitable solution.

4 Answers

1.) Create a variable (global variable/ provider) "failed attempts".

2.) On failed attempt increase value =+ 1. -> When user typed the correct password, delete the current count.

3.) When user failed 3 times -> save CurrentTime in the preference.

4.) Check it before attempting to login again. -> Current time < (5 Minutes) compared to saved time -> show popup "Sorry, you have to wait 5 minutes".

As nvoigt pointed out, you can/should store the variables in the backend, to increase security.

I would suggest using storage to store the DateTime of the last failed attempt after N number of failed attempts & checking if current time has passed X days or Y Hours or Z minutes and so on...

Note: While I am suggesting using the storage for this, it is just out of convinience for you to implement & get going. It is not reliable as the user can change device's date & time settings or can reset/clear storage data.

In case if you are looking for a more secure approach with the same technique use something like firebase DB & Internet time instead of local storage & device time.

What I want to do is if the user attempts multiple failed attempt to login assume for 3 times, I want Login to get disabled for 5 minutes to the user.

This logic must be placed in the backend. When you call the login method on the backend, the backend has to keep track of how many unsuccessful tries there were and then lock the account for a specified time. Make sure you send a specific error code about the account being locked for the period to the frontend, so the frontend can display it and notify the user that trying to login is pointless.

There is no need to block the frontend from trying though. A malicious attacker will work around your protection anyway and a normal user may have reasons to try again (maybe with a different account).

You can use Timer class (link) and set needed delay to it. Block button at incorrect login action and after time runs out set it available again.

Related