예제 #1
0
        private void ShowBiometricPrompt()
        {
            var executor        = ContextCompat.GetMainExecutor(this);
            var passwordStorage = new PasswordStorageManager(this);
            var callback        = new AuthenticationCallback();

            callback.Success += async(_, result) =>
            {
                string password;

                try
                {
                    password = passwordStorage.Fetch(result.CryptoObject.Cipher);
                }
                catch
                {
                    Toast.MakeText(this, Resource.String.genericError, ToastLength.Short);
                    return;
                }

                await AttemptUnlock(password);
            };

            callback.Failed += delegate
            {
                FocusPasswordText();
            };

            callback.Error += (_, result) =>
            {
                Toast.MakeText(this, result.Message, ToastLength.Short).Show();
                FocusPasswordText();
            };

            _prompt = new BiometricPrompt(this, executor, callback);

            var promptInfo = new BiometricPrompt.PromptInfo.Builder()
                             .SetTitle(GetString(Resource.String.unlock))
                             .SetSubtitle(GetString(Resource.String.unlockBiometricsMessage))
                             .SetNegativeButtonText(GetString(Resource.String.cancel))
                             .SetConfirmationRequired(false)
                             .SetAllowedAuthenticators(BiometricManager.Authenticators.BiometricStrong)
                             .Build();

            Cipher cipher;

            try
            {
                cipher = passwordStorage.GetDecryptionCipher();
            }
            catch
            {
                _canUseBiometrics            = false;
                _useBiometricsButton.Enabled = false;
                return;
            }

            _prompt.Authenticate(promptInfo, new BiometricPrompt.CryptoObject(cipher));
        }
예제 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activityLogin);

            var executor = ContextCompat.GetMainExecutor(this);
            var callback = new AuthenticationCallback();

            callback.Success += OnSuccess;
            callback.Error   += OnError;

            var prompt = new BiometricPrompt(this, executor, callback);

            var promptInfo = new BiometricPrompt.PromptInfo.Builder()
                             .SetTitle(GetString(Resource.String.login))
                             .SetSubtitle(GetString(Resource.String.loginMessage))
                             .SetDeviceCredentialAllowed(true)
                             .Build();

            prompt.Authenticate(promptInfo);
        }