예제 #1
0
        private async Task <bool> LoadPasswordFile()
        {
            string masterPass = "";
            bool   passerror;
            bool   isFirst = true;

            // Get saved password
            string savedPass = AppData.GetSavedUserPassword();

            if (!string.IsNullOrEmpty(savedPass))
            {
                if (!AppData.Authenticate(savedPass, out passerror, out masterPass))
                {
                    // If authenticate is failed by unknown error, it failed to load file.
                    if (!passerror)
                    {
                        return(false);
                    }
                    masterPass = "";
                    isFirst    = false;
                }
            }

            string d_userPass    = "";
            bool   d_savePassFlg = false;

            while (string.IsNullOrEmpty(masterPass))
            {
                // Show password dialog
                PasswordDialog d = new PasswordDialog();
                d.Password     = d_userPass;
                d.SavePassword = d_savePassFlg;
                d.IsFirstTime  = isFirst;
                await d.ShowAsync();

                // If canceled, failed to load file.
                if (!d.IsOK)
                {
                    return(false);
                }
                d_userPass    = d.Password;
                d_savePassFlg = d.SavePassword;

                if (!AppData.Authenticate(d_userPass, out passerror, out masterPass))
                {
                    // If authenticate is failed by unknown error, it failed to load file.
                    if (!passerror)
                    {
                        return(false);
                    }
                    masterPass = "";
                    isFirst    = false;
                }
            }

            // If authenticated and save password flag is specified, save inputed password string
            if (d_savePassFlg)
            {
                AppData.SaveUserPassword(d_userPass);
            }

            // Load password file
            PasswordFile pf = new PasswordFile();

            if (pf.Load(masterPass))
            {
                // hold opened password file
                m_PasswordFile = pf;
            }
            else
            {
                // If failed to file, create new empty file.
                m_PasswordFile = new PasswordFile();
            }

            // hold master password string for future saving
            m_Password                 = masterPass;
            m_LastEditDate             = DateTime.UtcNow;
            EditEnableToggle.OnContent = SAVED_LABEL_TEXT;

            return(true);
        }
예제 #2
0
        // Load password file
        private static async Task <Tuple <PasswordFile, string> > LoadSelectedPasswordFile()
        {
            // Get stored password
            string savedPass  = AppData.GetSavedUserPassword();
            string masterPass = "";
            bool   passerror;
            bool   isFirst = true;

            if (!string.IsNullOrEmpty(savedPass))
            {
                if (!AppData.Authenticate(savedPass, out passerror, out masterPass))
                {
                    if (!passerror)
                    {
                        // Unexpected error
                        return(new Tuple <PasswordFile, string>(null, ""));
                    }
                    masterPass = "";
                    isFirst    = false;
                }
            }

            string d_userPass    = "";
            bool   d_savePassFlg = false;

            while (string.IsNullOrEmpty(masterPass))
            {
                // Show password dialog
                PasswordDialog d = new PasswordDialog();
                d.Password     = d_userPass;
                d.SavePassword = d_savePassFlg;
                d.IsFirstTime  = isFirst;
                await d.ShowAsync();

                // If canceled, failed to load file
                if (!d.IsOK)
                {
                    return(new Tuple <PasswordFile, string>(null, ""));
                }
                d_userPass    = d.Password;
                d_savePassFlg = d.SavePassword;

                if (!AppData.Authenticate(d_userPass, out passerror, out masterPass))
                {
                    if (!passerror)
                    {
                        // Unexpected error
                        return(new Tuple <PasswordFile, string>(null, ""));
                    }
                    // Retry
                    masterPass = "";
                    isFirst    = false;
                }
            }

            // If authenticated and save password flag is specified, save inputed password string
            if (d_savePassFlg)
            {
                AppData.SaveUserPassword(d_userPass);
            }

            PasswordFile pwFile     = new PasswordFile();
            bool         loadResult = pwFile.Load(masterPass);

            if (!loadResult)
            {
                // Unexpected error
                return(new Tuple <PasswordFile, string>(null, ""));
            }

            return(new Tuple <PasswordFile, string>(pwFile, masterPass));
        }