/// <summary> /// Method invoked when the user clicks on Use Windows Hello. /// Checks user's trustworthiness and enable Windows Hello. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void CheckBox_Click(object sender, RoutedEventArgs e) { if (UseWindowsHelloCheckBox.IsChecked == true) { if (await SecurityExtensions.Authenticate()) { UseWindowsHelloCheckBox.IsChecked = true; SecurityExtensions.RegisterKey(); } else { UseWindowsHelloCheckBox.IsChecked = false; SecurityExtensions.RemoveKey(); } } else { SecurityExtensions.RemoveKey(); } }
/// <summary> /// Method invoked when the user clicks on Accedi. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Button_Click(object sender, RoutedEventArgs e) { StatusProgressBar.Opacity = 1; UsernameTextBox.IsEnabled = false; PasswordPasswordBox.IsEnabled = false; LoginButton.IsEnabled = false; bool authenticated; try { if (ApplicationData.Current.LocalSettings.Values.ContainsKey("HelloAuthenticationEnabled")) { if (await SecurityExtensions.Authenticate()) { authenticated = await Singleton <ClientExtensions> .Instance.AuthenticateAndInitDataAsync(new UserCredentials(UsernameTextBox.Text, PasswordPasswordBox.Password), true); } else { PasswordPasswordBox.Password = ""; UsernameTextBox.IsEnabled = true; PasswordPasswordBox.IsEnabled = true; LoginButton.IsEnabled = true; StatusProgressBar.Opacity = 0; return; } } else { authenticated = await Singleton <ClientExtensions> .Instance.AuthenticateAndInitDataAsync(new UserCredentials(UsernameTextBox.Text, PasswordPasswordBox.Password), true); } SecurityExtensions.AddCredentials(UsernameTextBox.Text, PasswordPasswordBox.Password); BackgroundTaskExtensions.Register(120); } catch (Exception ex) { Analytics.TrackEvent(ex.Message, new Dictionary <string, string> { { "exception", ex.ToString() } }); AppNotification.IsOpen = true; AppNotification.Title = "Attention".GetLocalized(); if (ex is UnauthorizedUserException) { AppNotification.Subtitle = ex.Message; UsernameTextBox.IsEnabled = true; PasswordPasswordBox.IsEnabled = true; LoginButton.IsEnabled = true; StatusProgressBar.Opacity = 0; return; } else if (ex is HttpRequestException) { AppNotification.Subtitle = "HttpRequestException".GetLocalized(); UsernameTextBox.IsEnabled = true; PasswordPasswordBox.IsEnabled = true; LoginButton.IsEnabled = true; StatusProgressBar.Opacity = 0; return; } else { AppNotification.Subtitle = "UnhandledException".GetLocalized(); } } NavigationService.Navigate(typeof(MainPage), new EntranceNavigationTransitionInfo()); navigationView.SelectedItem = navigationView.MenuItems[0]; IsBackEnabled = false; NavigationService.Frame.BackStack.Clear(); Loader.IsLoading = false; _avoidCheck = false; UsernameTextBox.IsEnabled = true; PasswordPasswordBox.IsEnabled = true; LoginButton.IsEnabled = true; StatusProgressBar.Opacity = 0; }