Пример #1
0
        /// <summary>
        /// Method which removes the credentials from the Windows vault stored by the application.
        /// </summary>
        internal static void RemoveCredentials()
        {
            BackgroundTaskExtensions.Unregister();

            DisableWindowsHello();

            PasswordCredential credential = RetrieveCredentials();

            if (credential != null)
            {
                credential.RetrievePassword();

                new PasswordVault().Remove(new PasswordCredential(ResourceLoader.GetForCurrentView().GetString("AppName"), credential.UserName, credential.Password));
            }
        }
Пример #2
0
        /// <summary>
        /// Method which stores the credentials into the Windows vault.
        /// </summary>
        /// <param name="username">The username</param>
        /// <param name="password">The password</param>
        internal static void AddCredentials(string username, string password)
        {
            new PasswordVault().Add(new PasswordCredential(ResourceLoader.GetForCurrentView().GetString("AppName"), username, password));

            BackgroundTaskExtensions.Register();
        }
Пример #3
0
        /// <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;
        }