private void Authenticate() { bool Validation = true; lblUsernameError.Content = ""; lblPasswordError.Content = ""; try { if (string.IsNullOrWhiteSpace(txtUsername.Text)) { Validation = false; lblUsernameError.Content = "is mandatory."; } if (string.IsNullOrWhiteSpace(txtPassword.Password)) { Validation = false; lblPasswordError.Content = "is mandatory."; } if (Validation && BL_Users.Authenticate(new Loginmodel() { CredentialName = txtUsername.Text, Password = txtPassword.Password })) { new MainWindow().Show(); this.Close(); } else { throw new Exception("Authentication failed. Please check your credentials"); } } catch (UserNotFoundException ex) { lblUsernameError.Content = ex.Message; } catch (Exception ex) { lblAuthError.Content = ex.Message; } ShowPassword = false; TogglePassword(); txtUsername.Focus(); }