Esempio n. 1
0
        private async void OnSetPasswordButtonClick(object sender, EventArgs e)
        {
            if (_passwordText.Text != _passwordConfirmText.Text)
            {
                _passwordConfirmLayout.Error = GetString(Resource.String.passwordsDoNotMatch);
                return;
            }

            var newPassword = _passwordText.Text == "" ? null : _passwordText.Text;

            _setPasswordButton.Enabled = _cancelButton.Enabled = false;
            _setPasswordButton.SetText(newPassword != null ? Resource.String.encrypting : Resource.String.decrypting);
            SetCancelable(false);

            try
            {
                var currentPassword = await SecureStorageWrapper.GetDatabasePassword();

                await Database.SetPassword(currentPassword, newPassword);

                try
                {
                    await SecureStorageWrapper.SetDatabasePassword(newPassword);
                }
                catch
                {
                    // Revert changes
                    await Database.SetPassword(newPassword, currentPassword);

                    throw;
                }
            }
            catch
            {
                Toast.MakeText(Context, Resource.String.genericError, ToastLength.Short).Show();
                SetCancelable(true);
                UpdateSetPasswordButton();
                _cancelButton.Enabled = true;
                return;
            }

            _preferences.AllowBiometrics   = false;
            _preferences.PasswordProtected = newPassword != null;
            _preferences.PasswordChanged   = true;

            try
            {
                var manager = new PasswordStorageManager(Context);
                manager.Clear();
            }
            catch
            {
                // Not really an issue if this fails
            }

            await((SettingsActivity)Context).BaseApplication.Unlock(newPassword);
            Dismiss();
        }
Esempio n. 2
0
 private void UpdateUi()
 {
     if (!isPinging)
     {
         progress.Visibility = ViewStates.Invisible;
         btnRetry.Enabled    = true;
         btnRetry.SetText(retryText1);
         noNetHeader.SetText(headerText1);
         noNetSub.SetText(subTitle1);
     }
     else
     {
         progress.Visibility = ViewStates.Visible;
         btnRetry.Enabled    = false;
         btnRetry.SetText(retryText2);
         noNetHeader.SetText(headerText2);
         noNetSub.SetText(subTitle2);
     }
 }
        private async void OnSetPasswordButtonClick(object sender, EventArgs args)
        {
            if (_passwordText.Text != _passwordConfirmText.Text)
            {
                _passwordConfirmLayout.Error = GetString(Resource.String.passwordsDoNotMatch);
                return;
            }

            var newPassword = _passwordText.Text == "" ? null : _passwordText.Text;

            _setPasswordButton.Enabled = _cancelButton.Enabled = false;
            _setPasswordButton.SetText(newPassword != null ? Resource.String.encrypting : Resource.String.decrypting);
            _progressBar.Visibility = ViewStates.Visible;
            SetCancelable(false);

            try
            {
                var currentPassword = await SecureStorageWrapper.GetDatabasePassword();

                await _database.SetPassword(currentPassword, newPassword);

                try
                {
                    await SecureStorageWrapper.SetDatabasePassword(newPassword);
                }
                catch
                {
                    // Revert changes
                    await _database.SetPassword(newPassword, currentPassword);

                    throw;
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);

                Toast.MakeText(Context, Resource.String.genericError, ToastLength.Short).Show();
                _progressBar.Visibility = ViewStates.Invisible;
                SetCancelable(true);
                UpdateSetPasswordButton();
                _cancelButton.Enabled = true;
                return;
            }

            _preferences.AllowBiometrics   = false;
            _preferences.PasswordProtected = newPassword != null;
            _preferences.PasswordChanged   = true;

            if (newPassword == null && _preferences.DatabasePasswordBackup)
            {
                _preferences.DatabasePasswordBackup = false;
            }

            try
            {
                var manager = new PasswordStorageManager(Context);
                manager.Clear();
            }
            catch (Exception e)
            {
                // Not really an issue if this fails
                Logger.Error(e);
            }

            Dismiss();
        }