Exemplo n.º 1
0
        private async void ChangePasswordButton_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;
            _ = e;

            // Show password dialog at first time.
            SetNewPassDialog d = new SetNewPassDialog(true, false);

            d.Password = "";
            await d.ShowAsync();

            // If canceled, give up to change password.
            if (!d.IsOK)
            {
                return;
            }

            string currentPass = d.OldPassword;
            string newPass     = d.Password;
            bool   saveFlg     = d.SavePassword;

            // Try to change password, and if failed, request new password again.
            while (!AppData.ChangeUserPassword(currentPass, newPass))
            {
                // Show dialog
                d              = new SetNewPassDialog(true, true);
                d.Password     = newPass;
                d.SavePassword = saveFlg;
                await d.ShowAsync();

                // If canceled, give up to change password.
                if (!d.IsOK)
                {
                    return;
                }

                currentPass = d.OldPassword;
                newPass     = d.Password;
                saveFlg     = d.SavePassword;
            }

            if (saveFlg)
            {
                // If save password flag is set, save new password string.
                AppData.SaveUserPassword(newPass);
            }
            else
            {
                // If save password flag is not set, clear saved old password.
                AppData.ClearSavedUserPassword();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// CreateNewPasswordFileButton button was selected.
        /// </summary>
        private async void CreateNewPasswordFileButton_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;
            _ = e;

            ResourceLoader r = ResourceLoader.GetForCurrentView();

            if (await AppData.IsInitialized().ConfigureAwait(true))
            {
                // Clear existing account information and set new password

                string titleStr = null;
                if (null != r)
                {
                    titleStr = r.GetString("INIT_CONFIRM_MSG_TITLE");
                }
                if (null == titleStr)
                {
                    titleStr = "Confirmation";
                }

                string msgStr = null;
                if (null != r)
                {
                    msgStr = r.GetString("INIT_CONFIRM_MSG");
                }
                if (null == msgStr)
                {
                    msgStr = "All registered data will be deleted, including backup. Do you want to run it?";
                }

                MessageDialog msgDlg      = new MessageDialog(msgStr, titleStr);
                string        okLabel     = GlbFunc.GetResourceString("CONFIRM_INITIALIZE_OK_MSG", "OK");
                string        cancelLabel = GlbFunc.GetResourceString("CONFIRM_INITIALIZE_CANCEL_MSG", "Cancel");
                msgDlg.Commands.Add(new UICommand(okLabel));
                msgDlg.Commands.Add(new UICommand(cancelLabel));
                var result = await msgDlg.ShowAsync();

                if (result.Label != okLabel)
                {
                    return;
                }

                // Get the password of the new file.
                SetNewPassDialog newPassDlg = new SetNewPassDialog(false, false);
                await newPassDlg.ShowAsync();

                if (!newPassDlg.IsOK)
                {
                    return;
                }
                AppData.Initialize(newPassDlg.Password, newPassDlg.SavePassword);
            }
            else
            {
                // Specify new password and initialize data structure.

                // Get the password of the new file.
                SetNewPassDialog d = new SetNewPassDialog(false, false);
                await d.ShowAsync();

                if (!d.IsOK)
                {
                    return;
                }
                AppData.Initialize(d.Password, d.SavePassword);
            }
            await UpdateWindowStat().ConfigureAwait(true);
        }