Hi,
I have a similar code for invalid login attemps, check below code
private static int cntAttemps = 0;
private void LoginUser()
{
try
{
string userEmail = string.IsNullOrEmpty(txtUserEmail.Text) ? null : txtUserEmail.Text;
string password = string.IsNullOrEmpty(txtPassword.Text) ? null : txtPassword.Text;
bool success = CheckLogin(userEmail, password);
if (!success)
{
lblInvalidmsg.Text = string.Empty;
InvalidLoginAttemps();
}
else
{
cntAttemps = 1;
dvinvalid.Visible = false;
lblInvalidmsg.Text = string.Empty;
}
}
catch (Exception ex)
{
}
}
private void InvalidLoginAttemps()
{
try
{
dvinvalid.Visible = true;
cntAttemps++;
lblInvalidmsg.Text = "Invalid login attemp(s) " + cntAttemps + ", attemps remaining " + Convert.ToInt32(3 - cntAttemps).ToString();
if (cntAttemps > 3)
{
lblInvalidmsg.Text = "Sorry! your account is block now, please contact your administrator.";
}
}
catch (Exception ex)
{
}
}
Here
CheckLogin
is your login method to compare credentials from
web.config
will return
true
if success.