Esempio n. 1
0
        public async Task <UserConsentVerificationResult> GetRequestUserConsentVerificationAsync(string message)
        {
            UserConsentVerificationResult consentResult =
                await UserConsentVerifier.RequestVerificationAsync(message);

            return(consentResult);
        }
        /// <summary>
        /// Request for user's consent with prompt given.
        /// </summary>
        /// <param name="prompt">The prompt which is shown during verification.</param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public static async Task <bool> RequestUserConsent(string prompt)
        {
            // If verification is not available, always return true.
            if (!await CheckAvailabilityAsync())
            {
                return(true);
            }

            var app = Application.Current as App;

            if (app == null)
            {
                return(false);
            }

            var resourceLoader = app.Container.Resolve <IResourceLoader>();

            if (string.IsNullOrEmpty(prompt))
            {
                prompt = resourceLoader.GetString(ResourceConstants.VerificationService_Prompt);
            }

            try
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync(prompt);

                return(consentResult == UserConsentVerificationResult.Verified);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Verifies the user's identity and retrieves the selected profile's passphrase
        /// </summary>
        /// <param name="profileId"></param>
        private async Task PromptForConsent(ProfileModel profile)
        {
            // Create instance to credential locker
            var locker    = new PasswordVault();
            var profileId = profile.Id.ToString();

            try
            {
                // Find the saved passphrase for the selected profile
                var login = GetSavedCredential(locker, profileId);
                if (login != null)
                {
                    // We have a stored passphrase, verify the user's identity before releasing it.
                    var consentResult = await UserConsentVerifier.RequestVerificationAsync(ResourceHelper.GetString("WindowsHelloConsentMessage"));

                    if (consentResult == UserConsentVerificationResult.Verified)
                    {
                        // Verified. Get the passphrase.
                        login.RetrievePassword();

                        // Enter the profile with the saved passphrase
                        await EnterProfile(profile, login.Password);

                        return;
                    }
                }
            }
            catch { /* Nothing to see here */ }
        }
Esempio n. 4
0
        private async Task <bool> AuthenticateAsync()
        {
            ErrorMessage.Visibility = Visibility.Collapsed;
            FirstErrorMessage       = string.Empty;

            try
            {
                var res = await UserConsentVerifier.RequestVerificationAsync("tSecret");

                switch (res)
                {
                case UserConsentVerificationResult.Verified:
                    ConfigUtil.Set("LoginUtc", DateTime.UtcNow.ToString());
                    this.Frame.Navigate(typeof(NoteListPage), null, new SlideNavigationTransitionInfo
                    {
                        Effect = SlideNavigationTransitionEffect.FromRight,
                    });
                    return(true);

                default:
                    ErrorMessage.Text       = "Authentication error";
                    ErrorMessage.Visibility = Visibility.Visible;
                    return(false);
                }
            }
            catch (Exception)
            {
                ErrorMessage.Text       = "ERROR: Cannot use tSecret on this platform";
                ErrorMessage.Visibility = Visibility.Visible;
                StartButton.IsEnabled   = false;
                return(false);
            }
        }
Esempio n. 5
0
        public static async Task <bool> VerifyAsync(string setting, string displayReason)
        {
            if ((DateTimeOffset.Now - App.RoamingSettings.Read("LastVerified", DateTimeOffset.MinValue)) <= App.RoamingSettings.Read(AUTHENTICATION_TIME, TimeSpan.FromMinutes(5)))
            {
                return(true);
            }

            if (!App.RoamingSettings.Read(setting, false))
            {
                return(true);
            }

            var available = await UserConsentVerifier.CheckAvailabilityAsync();

            if (available == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync(displayReason);

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    App.RoamingSettings.Save("LastVerified", DateTimeOffset.Now);
                    return(true);
                }
            }
            else
            {
                return(true);
            }

            return(false);
        }
        private async void RequestConsent_Click(object sender, RoutedEventArgs e)
        {
            RequestConsentButton.IsEnabled = false;

            // Request the user's consent using Windows Hello via biometric verification or a PIN.
            string message = "Please confirm your identity to complete this (pretend) in-app purchase.";
            UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(message);

            switch (consentResult)
            {
            case UserConsentVerificationResult.Verified:
                rootPage.NotifyUser("Pretend in-app purchase was successful.", NotifyType.StatusMessage);
                break;

            case UserConsentVerificationResult.DeviceNotPresent:
                rootPage.NotifyUser("No PIN or biometric found, please set one up.", NotifyType.ErrorMessage);
                break;

            case UserConsentVerificationResult.Canceled:
                rootPage.NotifyUser("User consent verification canceled.", NotifyType.ErrorMessage);
                break;

            default:
                rootPage.NotifyUser("User consent verification is currently unavailable.", NotifyType.ErrorMessage);
                break;
            }
            RequestConsentButton.IsEnabled = true;
        }
        /// <summary>
        /// Verifies the user's identity.
        /// </summary>
        /// <returns>True if identity was verified, else false.</returns>
        public async Task <bool> VerifyIdentityAsync()
        {
            UserConsentVerificationResult result =
                await UserConsentVerifier.RequestVerificationAsync(
                    this.resourceProvider.GetString(PromptResourceKey)
                    );

            return(result == UserConsentVerificationResult.Verified);
        }
Esempio n. 8
0
        private async Task verify()
        {
            string info    = null;
            var    succeed = false;
            var    result  = await UserConsentVerifier.RequestVerificationAsync(Strings.Resources.Verify.Dialog.Content);

            switch (result)
            {
            case UserConsentVerificationResult.Verified:
                succeed = true;
                break;

            case UserConsentVerificationResult.DeviceNotPresent:
                info = Strings.Resources.Verify.DeviceNotPresent;
                break;

            case UserConsentVerificationResult.NotConfiguredForUser:
                info = Strings.Resources.Verify.NotConfigured;
                break;

            case UserConsentVerificationResult.DisabledByPolicy:
                info = Strings.Resources.Verify.Disabled;
                break;

            case UserConsentVerificationResult.DeviceBusy:
                info = Strings.Resources.Verify.DeviceBusy;
                break;

            case UserConsentVerificationResult.RetriesExhausted:
                info = Strings.Resources.Verify.RetriesExhausted;
                break;

            case UserConsentVerificationResult.Canceled:
                info = Strings.Resources.Verify.Canceled;
                break;

            default:
                info = Strings.Resources.Verify.OtherFailure;
                break;
            }
            if (!succeed)
            {
                if (info != null)
                {
                    var dialog = new MyContentDialog
                    {
                        Title           = Strings.Resources.Verify.FailedDialogTitle,
                        Content         = info,
                        CloseButtonText = Strings.Resources.General.Exit,
                    };
                    await dialog.ShowAsync();
                }
                Application.Current.Exit();
            }
        }
Esempio n. 9
0
        public async Task <bool> Authenticate()
        {
            var res = await UserConsentVerifier.RequestVerificationAsync("tSecret");

            switch (res)
            {
            case UserConsentVerificationResult.Verified:
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Method which requests user authentication with Windows Hello if any athentication device
        /// is available.
        /// </summary>
        /// <returns>The authentication status</returns>
        internal async static Task <bool> Authenticate()
        {
            UserConsentVerifierAvailability userConsentVerifierAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            switch (userConsentVerifierAvailability)
            {
            // TODO: Implement other UserConsentVerifierAvailability cases
            case UserConsentVerifierAvailability.Available:
                return(await UserConsentVerifier.RequestVerificationAsync("WindowsHelloMessage".GetLocalized()) == UserConsentVerificationResult.Verified);

            default:
                return(false);
            }
        }
Esempio n. 11
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            args.Cancel = true;
            var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            if (ucvAvailability == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync(this.Title.ToString());

                this.Success = (consentResult == UserConsentVerificationResult.Verified);
                this.Hide();
                return;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Verify login with Windows Hello
        /// </summary>
        private async void WindowsHelloLogin()
        {
            UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(Resources.WindowsHelloLoginMessage);

            if (consentResult.Equals(UserConsentVerificationResult.Verified))
            {
                var dbHash = await App.Repository.Password.GetAsync();

                var secretService = App.Current.Container.Resolve <ISecretService>();
                //TODO check if this is a problem
                if (!await CheckNavigationRequest(secretService.Helper.ReadSecret(Constants.ContainerName, dbHash.Hash)))
                {
                    ShowLoginError();
                }
            }
        }
Esempio n. 13
0
        private async void buttonRequestConsent_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("我要做一些操作,您同意吗?");

                switch (consentResult)
                {
                case UserConsentVerificationResult.Verified:     // 验证通过
                    lblMsg.Text += "UserConsentVerificationResult.Verified";
                    break;

                case UserConsentVerificationResult.DeviceBusy:
                    lblMsg.Text += "UserConsentVerificationResult.DeviceBusy";
                    break;

                case UserConsentVerificationResult.DeviceNotPresent:
                    lblMsg.Text += "UserConsentVerificationResult.DeviceNotPresent";
                    break;

                case UserConsentVerificationResult.DisabledByPolicy:
                    lblMsg.Text += "UserConsentVerificationResult.DisabledByPolicy";
                    break;

                case UserConsentVerificationResult.NotConfiguredForUser:
                    lblMsg.Text += "UserConsentVerificationResult.NotConfiguredForUser";
                    break;

                case UserConsentVerificationResult.RetriesExhausted:
                    lblMsg.Text += "UserConsentVerificationResult.RetriesExhausted";
                    break;

                case UserConsentVerificationResult.Canceled:     // 验证取消
                    lblMsg.Text += "UserConsentVerificationResult.Canceled";
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                lblMsg.Text += ex.ToString();
            }

            lblMsg.Text += "\n";
        }
Esempio n. 14
0
        private async void CreateAccountButton_Click(object sender, RoutedEventArgs e)
        {
            if (personalInfo == null)
            {
                var uri = new Uri(@"https://app.n26.com/register");
                await Windows.System.Launcher.LaunchUriAsync(uri);
            }
            else
            {
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("Please authenticate to log in!");

                if (consentResult.Equals(UserConsentVerificationResult.Verified))
                {
                    SendLogin(GetCredentialFromLocker().UserName, GetCredentialFromLocker().Password);
                }
            }
        }
Esempio n. 15
0
        private void DeviceAuthentication(StoryNode cut)
        {
            var t1 = UserConsentVerifier.CheckAvailabilityAsync().AsTask();

            t1.ContinueWith(delegate
            {
                var available = t1.Result;
                if (available == UserConsentVerifierAvailability.Available)
                {
                    _ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var t2 = UserConsentVerifier.RequestVerificationAsync("tSecret").AsTask();
                        t2.ContinueWith(delegate
                        {
                            if (t2.Result == UserConsentVerificationResult.Verified)
                            {
                                ConfigUtil.Set("LoginUtc", DateTime.UtcNow.ToString());
                                cut.TaskResult = true;
                            }
                            else
                            {
                                cut.MessageBuffer.WriteLine($"PIN Authentication stopped : {t2.Result}");
                                cut.TaskResult = false;
                            }
                        });
                    });
                }
                else
                {
                    cut.MessageBuffer.WriteLine($"PIN Authentication is not available.");
                    cut.MessageBuffer.WriteLine($"(E902)");
                    cut.TaskResult = false;
                }
            });
            //        catch (Exception ex)
            //        {
            //            cut.MessageBuffer.WriteLine($"Local Authentication exception");
            //            cut.MessageBuffer.WriteLine($"(E901-2)");
            //            cut.MessageBuffer.WriteLine(ex.Message);
            //            cut.TaskResult = false;
            //        }
        }
Esempio n. 16
0
        public async Task <FingerprintAuthenticationResult> AuthenticateAsync(string reason, CancellationToken cancellationToken)
        {
            var result = new FingerprintAuthenticationResult();

            try
            {
                var verificationResult = await UserConsentVerifier.RequestVerificationAsync(reason);

                switch (verificationResult)
                {
                case UserConsentVerificationResult.Verified:
                    result.Status = FingerprintAuthenticationResultStatus.Succeeded;
                    break;

                case UserConsentVerificationResult.DeviceBusy:
                case UserConsentVerificationResult.DeviceNotPresent:
                case UserConsentVerificationResult.DisabledByPolicy:
                case UserConsentVerificationResult.NotConfiguredForUser:
                    result.Status = FingerprintAuthenticationResultStatus.NotAvailable;
                    break;

                case UserConsentVerificationResult.RetriesExhausted:
                    result.Status = FingerprintAuthenticationResultStatus.Failed;
                    break;

                case UserConsentVerificationResult.Canceled:
                    result.Status = FingerprintAuthenticationResultStatus.Canceled;
                    break;

                default:
                    result.Status = FingerprintAuthenticationResultStatus.NotAvailable;
                    break;
                }
            }
            catch (Exception ex)
            {
                result.Status       = FingerprintAuthenticationResultStatus.UnknownError;
                result.ErrorMessage = ex.Message;
            }

            return(result);
        }
Esempio n. 17
0
        public static async Task <bool> ChallengeWindowsHelloAsync()
        {
            if (await UserConsentVerifier.CheckAvailabilityAsync() == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync("Let's make sure you're authorized to make changes");

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    return(true);
                }
            }


            // Fallback
            var dialog = new MessageDialog("Make sure Windows Hello has been already set up first.", "You are not authorized");

            await dialog.ShowAsync();

            return(false);
        }
Esempio n. 18
0
        // Add reference to Windows.winmd, typically c:\program files (x86)\windows kits\10\UnionMetadata\{version}
        // Add reference to System.Runtime.WindowsRuntime.dll, typically C:\Windows\Microsoft.NET\Framework\v4.0.30319
        public async Task <bool> WindowsHelloSignInAsync()
        {
            // Check the availability of Windows Hello authentication through User Consent Verifier.
            UserConsentVerifierAvailability consentAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

            if (consentAvailability == UserConsentVerifierAvailability.Available)
            {
                // Request the user's consent using Windows Hello via biometric verification or a PIN.
                string message = "Please confirm your identity to login to this app";
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(message);

                switch (consentResult)
                {
                case UserConsentVerificationResult.Verified:
                    System.Diagnostics.Debug.WriteLine("User verified");
                    return(true);
                }
            }
            return(false);
        }
        public async Task <bool> ConfirmUserConsent()
        {
            if (ApiInformation.IsTypePresent("Windows.Security.Credentials.UI.UserConsentVerifier"))
            {
                var ucvAvailability = await UserConsentVerifier.CheckAvailabilityAsync();

                if (ucvAvailability == UserConsentVerifierAvailability.Available)
                {
                    var ucvResult = await UserConsentVerifier.RequestVerificationAsync($"You are about to enter edit mode. Are you sure?");

                    return(ucvResult == UserConsentVerificationResult.Verified);
                }
            }
            else
            {
                return(true);
            }

            return(true);
        }
Esempio n. 20
0
        public async Task <bool> RequestUserConsentVerificationAsync(string message)
        {
            try
            {
                UserConsentVerificationResult consentResult =
                    await UserConsentVerifier.RequestVerificationAsync(message);

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 21
0
        public static async Task <bool> ChallengeWindowsHelloAsync()
        {
            if (await UserConsentVerifier.CheckAvailabilityAsync() == UserConsentVerifierAvailability.Available)
            {
                var consentResult = await UserConsentVerifier.RequestVerificationAsync("DeviceSecurity_ChallengeWindowsHelloRequest/Description".GetLocalized());

                if (consentResult == UserConsentVerificationResult.Verified)
                {
                    return(true);
                }
            }


            // Fallback
            var dialog = new MessageDialog("DeviceSecurity_ChallengeWindowsHelloError/Description".GetLocalized(),
                                           "DeviceSecurity_ChallengeWindowsHelloError/Title".GetLocalized());

            await dialog.ShowAsync();

            return(false);
        }
        public static async Task <bool> Auth()
        {
            if (await WindowsHelloAvailableCheckAsync())
            {
                UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync("");

                if (consentResult != UserConsentVerificationResult.Verified)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                await new MessageDialog("Failed loading Windows Hello service", "Failed").ShowAsync();
                await Launcher.LaunchUriAsync(new Uri("ms-settings:signinoptions"));
            }
            return(false);
        }
Esempio n. 23
0
        /// <summary>
        /// Method invoked when the user clicks on Usa 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 (WindowsHelloCheckBox.IsChecked == true)
            {
                if (await UserConsentVerifier.RequestVerificationAsync(SecurityExtensions.MESSAGE) == UserConsentVerificationResult.Verified)
                {
                    WindowsHelloCheckBox.IsChecked = true;

                    SecurityExtensions.EnableWindowsHello();
                }
                else
                {
                    WindowsHelloCheckBox.IsChecked = false;

                    SecurityExtensions.DisableWindowsHello();
                }
            }
            else
            {
                SecurityExtensions.DisableWindowsHello();
            }
        }
Esempio n. 24
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            personalInfo = await api.LoadMe();

            if (personalInfo != null)
            {
                WelcomeBlock.Text           = string.Format("Welcome back, {0}!", personalInfo.firstName);
                UsernameBox.Text            = personalInfo.email;
                CreateAccountButton.Content = "Login using Windows Hello";
            }
            else
            {
                return;
            }

            var loginCredential = GetCredentialFromLocker();

            if (loginCredential == null)
            {
                return;
            }


            UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(string.Format("Welcome back, {0}!", personalInfo.firstName));

            if (consentResult.Equals(UserConsentVerificationResult.Verified))
            {
                ProgressWorking.Visibility = Visibility.Visible;
                if (await api.RenewToken())
                {
                    LoadData();
                }
                else
                {
                    await new MessageDialog("We've lost authentication. Please log in again!").ShowAsync();
                }
            }
        }
Esempio n. 25
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            PasswordVault vault = new PasswordVault();

            try
            {
                var creds = vault.FindAllByResource(App.RL.GetString("CredResName"));
                if (creds.Count > 0)
                {
                    SetLoading();

                    var idVerificationPossible = await UserConsentVerifier.CheckAvailabilityAsync();

                    var localSettings = ApplicationData.Current.LocalSettings.Values;

                    bool goodToGo = true;

                    if (idVerificationPossible == UserConsentVerifierAvailability.Available && (bool)(localSettings[App.RL.GetString("VerifyIdSettingString")] ?? false))
                    {
                        var verified =
                            await
                            UserConsentVerifier.RequestVerificationAsync(
                                "Just need to double check that it's you before we login :)");

                        goodToGo = verified == UserConsentVerificationResult.Verified;

                        if (verified == UserConsentVerificationResult.RetriesExhausted)
                        {
                            foreach (var cred in creds)
                            {
                                vault.Remove(cred);
                            }
                            await
                            new MessageDialog("For your safety, we've removed your saved login data.",
                                              "Too Many Failed Attempts").ShowAsync();
                        }

                        if (!goodToGo)
                        {
                            await new MessageDialog("Because you enabled identity verification, you will not be able to start the app without verification.", "We Couldn't Verify Your Identity").ShowAsync();
                            App.Current.Exit();
                        }
                    }

                    var connector = new MUConnector(creds.First());
                    if (await connector.Login())
                    {
                        App.MainViewModel.connector   = connector;
                        App.MainViewModel.SignOnSaved = true;
                        Frame.Navigate(typeof(FoodTile.Views.MainPage));
                    }
                    else
                    {
                        vault.Remove(creds.First());
                        await new MessageDialog(App.RL.GetString("SavedLoginFailMsg"), App.RL.GetString("SavedLoginFailTitle")).ShowAsync();
                    }


                    UnsetLoading();
                }
            }
            catch
            {
                //Used to handle the case when no credentials are found - safe to move on
            }

            base.OnNavigatedTo(e);
        }
Esempio n. 26
0
        public async Task <bool> Evaluate(string message)
        {
            var result = await UserConsentVerifier.RequestVerificationAsync(message);

            return(result == UserConsentVerificationResult.Verified);
        }
Esempio n. 27
0
        private async void PinPageHelper(LaunchActivatedEventArgs e)
        {
            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("cbExtLinks"))
            {
                UtilityData.isFirstAppRun = true;
                rootFrame.Navigate(typeof(OOBE), e.Arguments);
                return;
            }
            bool isWindows = false;

            try
            {
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("WindowsHello"))
                {
                    if ((bool)ApplicationData.Current.LocalSettings.Values["WindowsHello"] == true)
                    {
                        var result = await UserConsentVerifier.CheckAvailabilityAsync();

                        if (result == UserConsentVerifierAvailability.Available)
                        {
                            var verifiedResult = await UserConsentVerifier.RequestVerificationAsync("Just checking that you are really you :)");

                            if (verifiedResult == UserConsentVerificationResult.Verified)
                            {
                                rootFrame.Navigate(typeof(MainPage), e.Arguments);
                                isWindows = true;
                            }
                            else if (verifiedResult == UserConsentVerificationResult.Canceled)
                            {
                                Application.Current.Exit();
                            }
                        }
                    }
                }
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("defaultPin") && !isWindows)
                {
                    if ((bool)ApplicationData.Current.LocalSettings.Values["defaultPin"] == true)
                    {
                        string pinString = "";
                        try
                        {
                            if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("Password"))
                            {
                                StorageFile sampleFile = await ApplicationData.Current.LocalFolder.GetFileAsync("data.txt");

                                ApplicationData.Current.LocalSettings.Values["Password"] = await FileIO.ReadTextAsync(sampleFile);
                            }
                            pinString = ApplicationData.Current.LocalSettings.Values["Password"].ToString();
                        }
                        catch (Exception)
                        {
                        }
                        if (pinString != "")
                        {
                            rootFrame.Navigate(typeof(PinUI), e.Arguments);
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage), e.Arguments);
                        }
                    }
                    else
                    {
                        rootFrame.Navigate(typeof(MainPage), e.Arguments);
                    }
                }
                else
                {
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
            }
            catch (Exception)
            {
                rootFrame.Navigate(typeof(MainPage), e?.Arguments);
            }
        }
Esempio n. 28
0
        private async void CallUserConsentVerifier()
        {
            var x = await UserConsentVerifier.RequestVerificationAsync("Test Message");

            var y = await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync("Test Message");
        }
        /// <summary>
        /// This is the click handler for the 'Request Consent' button. It requests consent from the current user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void RequestConsent_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            b.IsEnabled = false;

            if (!String.IsNullOrEmpty(Message.Text))
            {
                try
                {
                    // Request the currently logged on user's consent via fingerprint swipe
                    UserConsentVerificationResult consentResult = await UserConsentVerifier.RequestVerificationAsync(Message.Text);

                    switch (consentResult)
                    {
                    case UserConsentVerificationResult.Verified:
                    {
                        rootPage.NotifyUser("User's presence verified.", NotifyType.StatusMessage);
                        break;
                    }

                    case UserConsentVerificationResult.DeviceBusy:
                    {
                        rootPage.NotifyUser("Biometric device is busy.", NotifyType.ErrorMessage);
                        break;
                    }

                    case UserConsentVerificationResult.DeviceNotPresent:
                    {
                        rootPage.NotifyUser("No biometric device found.", NotifyType.ErrorMessage);
                        break;
                    }

                    case UserConsentVerificationResult.DisabledByPolicy:
                    {
                        rootPage.NotifyUser("Biometrics is disabled by policy.", NotifyType.ErrorMessage);
                        break;
                    }

                    case UserConsentVerificationResult.NotConfiguredForUser:
                    {
                        rootPage.NotifyUser("User has no fingeprints registered.", NotifyType.ErrorMessage);
                        break;
                    }

                    case UserConsentVerificationResult.RetriesExhausted:
                    {
                        rootPage.NotifyUser("Too many failed attempts.", NotifyType.ErrorMessage);
                        break;
                    }

                    case UserConsentVerificationResult.Canceled:
                    {
                        rootPage.NotifyUser("Consent request prompt was canceled.", NotifyType.ErrorMessage);
                        break;
                    }

                    default:
                    {
                        rootPage.NotifyUser("Consent verification with fingerprints is currently unavailable.", NotifyType.ErrorMessage);
                        break;
                    }
                    }
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Request current user's consent failed with exception. Operation: RequestVerificationAsync, Exception: " + ex.ToString(), NotifyType.ErrorMessage);
                }
                finally
                {
                    b.IsEnabled = true;
                }
            }
            else
            {
                rootPage.NotifyUser("Empty Message String. Enter prompt string in the Message text field.", NotifyType.ErrorMessage);
                b.IsEnabled = true;
            }
        }
Esempio n. 30
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;

            try
            {
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("HelloAuthenticationEnabled"))
                {
                    switch (await UserConsentVerifier.RequestVerificationAsync(SecurityExtensions.MESSAGE))
                    {
                    case UserConsentVerificationResult.Verified:
                    {
                        await Singleton <ClientExtensions> .Instance.Authenticate(UsernameTextBox.Text, PasswordPasswordBox.Password);

                        break;
                    }

                    case UserConsentVerificationResult.DeviceNotPresent:
                    {
                        SecurityExtensions.RemoveCredentials();
                        await new MessageDialog("L'autenticazione sicura tramite Windows Hello è stata disabilitata a causa della mancanza di opzioni di accesso valide. Per poter riabilitare questa funzione è necessario specificare un metodo di autenticazione valido (PIN, impronta digitale o scansione dell'iride) nelle impostazioni di Windows.\n\nPer motivi di sicurezza le credenziali del tuo account iliad dovranno essere inserite manualmente per questa sessione.", "Attenzione").ShowAsync();
                        break;
                    }

                    default:
                    {
                        Application.Current.Exit();
                        break;
                    }
                    }
                }
                else
                {
                    await Singleton <ClientExtensions> .Instance.Authenticate(UsernameTextBox.Text, PasswordPasswordBox.Password);
                }

                SessionTimeout.Tick += (s, o) =>
                {
                    Singleton <ClientExtensions> .Instance.Authenticate(UsernameTextBox.Text, PasswordPasswordBox.Password); // Never await this method!
                };

                SecurityExtensions.AddCredentials(UsernameTextBox.Text, PasswordPasswordBox.Password);

                AppNotification.IsOpen = false;

                NavigationService.Navigate(typeof(MainPage), new EntranceNavigationTransitionInfo());
                navigationView.SelectedItem = navigationView.MenuItems[0];
                IsBackEnabled = false;
                NavigationService.Frame.BackStack.Clear();

                Loader.IsLoading = false;

                SessionTimeout.Start();
            }
            catch (Exception ex)
            {
                HandleExceptionNotification(ex);
            }

            _avoidCheck = false;

            UsernameTextBox.IsEnabled     = true;
            PasswordPasswordBox.IsEnabled = true;
            LoginButton.IsEnabled         = true;
            StatusProgressBar.Opacity     = 0;
        }