/// <summary> /// Logs in the user based, or sleeps the thread for 5 seconds on failed attempts /// </summary> static void LoginUserGUI() { int maxTries = 5; int currentTries = 0; while (currentTries < maxTries) { Console.Write("Type in your username:"******"password:"******"you have now logged in"); break; } } if (maxTries == currentTries) { Console.WriteLine("To many tries wait a bit to try again"); Thread.Sleep(5000); } }
protected void SubmitButton_Click(object sender, EventArgs e) { int currentAttempts = 0; if (this.Request.Cookies["CurrentAttempts"] != null) { try { currentAttempts = int.Parse(Request.Cookies["CurrentAttempts"].Value); Response.Cookies.Add(new HttpCookie("CurrentAttempts", (currentAttempts + 1).ToString())); } catch { Thread.Sleep(5000); currentAttempts = 5; } } if (passwordService.CheckUserCredentials(UserName.Text, Password.Text)) { ShowPopUpMsg("Hello " + UserName.Text + ""); currentAttempts = 0; } else { ShowPopUpMsg("You have tried logging in, wrong username or password," + currentAttempts); currentAttempts++; } if (currentAttempts >= 5) { Thread.Sleep(5000); currentAttempts = 0; Response.Cookies.Add(new HttpCookie("CurrentAttempts", "0")); } }