Example #1
0
        /// <summary>
        /// Shows the fingerprint prompt without CryptoObject and allows the user to use the device PIN and password authentication.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickFingerAuthWithoutCrpObj(object sender, EventArgs e)
        {
            string Tag = "OnClickFingerAuthWithoutCrpObj";

            // Checks whether fingerprint authentication is available.
            BioAuthnManager bioAuthnManager = new BioAuthnManager(this);
            int             errorCode       = bioAuthnManager.CanAuth();

            if (errorCode != 0)
            {
                log.Info(Tag, "Can not authenticate. errorCode=" + errorCode);
                return;
            }

            // build prompt info
            BioAuthnPrompt.PromptInfo.Builder builder =
                new BioAuthnPrompt.PromptInfo.Builder().SetTitle("This is the title.")
                .SetSubtitle("This is the subtitle")
                .SetDescription("This is the description");

            // The user will first be prompted to authenticate with biometrics, but also given the option to
            // authenticate with their device PIN, pattern, or password. SetNegativeButtonText(CharSequence) should
            // not be set if this is set to true.
            builder.SetDeviceCredentialAllowed(true);

            // Set the text for the negative button. SetDeviceCredentialAllowed(true) should not be set if this button text
            // is set.
            // builder.SetNegativeButtonText("This is the 'Cancel' button.");

            BioAuthnPrompt.PromptInfo info = builder.Build();

            log.Info(Tag, "Start fingerprint authentication without CryptoObject.\nAuthenticating......\n");
            bioAuthnPrompt.Auth(info);
        }
Example #2
0
        /// <summary>
        /// Shows the fingerprint prompt with CryptoObject.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickFingerAuthWithCrpObj(object sender, EventArgs e)
        {
            string Tag = "FingerAuthWithCrpObj";

            BioAuthnManager bioAuthnManager = new BioAuthnManager(this);
            int             errorCode       = bioAuthnManager.CanAuth();

            if (errorCode != 0)
            {
                log.Info(Tag, "Can not authenticate. errorCode=" + errorCode);
                return;
            }

            // build prompt info
            BioAuthnPrompt.PromptInfo.Builder builder =
                new BioAuthnPrompt.PromptInfo.Builder().SetTitle("This is the title.")
                .SetSubtitle("This is the subtitle.")
                .SetDescription("This is the description.");

            // The user will first be prompted to authenticate with biometrics, but also given the option to
            // authenticate with their device PIN, pattern, or password. SetNegativeButtonText(string) should
            // not be set if this is set to true.
            // builder.SetDeviceCredentialAllowed(true);

            // Set the text for the negative button. SetDeviceCredentialAllowed(true) should not be set if this
            // button text is set.
            builder.SetNegativeButtonText("This is the 'Cancel' button.");

            BioAuthnPrompt.PromptInfo info = builder.Build();

            // Construct CryptoObject.
            Cipher cipher = new HwBioAuthnCipherFactory("hw_test_fingerprint", true).GetCipher();

            if (cipher == null)
            {
                log.Info(Tag, "Failed to create Cipher object.");
                return;
            }
            CryptoObject crypto = new CryptoObject(cipher);

            log.Info(Tag, "Start fingerprint authentication with CryptoObject.\nAuthenticating......\n");

            // When user CryptoObject, BiometricPrompt.PromptInfo.Builder.SetDeviceCredentialAllowed(true) is not allow.
            // Call BiometricPrompt.Authenticate(BiometricPrompt.PromptInfo info) if
            // BiometricPrompt.PromptInfo.Builder.SetDeviceCredentialAllowed(true) is set to true.
            Log.Info("CanAuth", bioAuthnManager.CanAuth().ToString());
            bioAuthnPrompt.Auth(info, crypto);
            Thread.Sleep(10000);
            bioAuthnPrompt.CancelAuth();
        }