private void TryLogin() { if (attemptsLeft < 1) { return; } // Do not count a log-in attempt if the user does not enter a username/password. if (txtLogUser.Text == "" || pswLogPassword.Password == "") { } if (IsLoginDataCorrect(txtLogUser.Text, pswLogPassword.Password)) { if (!DBMethods.LogRegRequests.DoesUse2FA(txtLogUser.Text, ref email)) { FinishLoggingIn(); } else { grd2FA.Visibility = Visibility.Visible; grdLog.HorizontalAlignment = HorizontalAlignment.Left; grdLog.Margin = new Thickness(100, 0, 0, 0); lblOutput.Foreground = new SolidColorBrush(Color.FromRgb(241, 241, 241)); lblOutput.Content = "Name/Password correct!\nPlease enter the authentication key\nwhich has just been emailed to you."; pswLogPassword.IsEnabled = false; txtLogUser.IsEnabled = false; btnLogIn.Content = "Resend code"; btnLogIn.Click -= BtnLogIn_Click; btnLogIn.Click += ResendCode_Click; authKey = EmailManagement.Send2FAEmail(email); } } else { if (attemptsLeft < 2) { txtLogUser.IsEnabled = false; txtLogUser.Text = ""; pswLogPassword.IsEnabled = false; pswLogPassword.Password = ""; lblOutput.Content = "You have been locked out from logging in."; btnLogIn.IsEnabled = false; return; } attemptsLeft--; lblOutput.Content = "Incorrect username/password!\nYou have " + attemptsLeft + " attempts left."; } }
private void ResendCode_Click(object sender, RoutedEventArgs e) { authKey = EmailManagement.Send2FAEmail(email); }