示例#1
0
        // Specify user pasword and initialize relative data structure.
        public static bool Initialize(string userPass, bool saveUserPass)
        {
            // Clear saved old data
            ApplicationData.Current.LocalSettings.Values.Clear();

            // Create new master password string
            Random        r          = new Random();
            StringBuilder masterPass = new StringBuilder();

            for (int i = 0; i < 64; i++)
            {
                char c = (char)(r.Next(1, 254) * 8 + r.Next(1, 254));
                masterPass.Append(c);
            }
            string masterPassStr = masterPass.ToString();

            // Save master password string
            ApplicationData.Current.LocalSettings.Values[MASTERPASS_KEYNAME] =
                Crypt.Base64Encoding(Crypt.CipherEncryption(masterPassStr, userPass, false));

            // if user password saving is specified, encrypt user password by fixed string
            if (saveUserPass)
            {
                SaveUserPassword(userPass);
            }

            // Create empty current file.
            PasswordFile pf = new PasswordFile();

            return(Save(masterPassStr, pf.BuildStringForOutput(false)));
        }
示例#2
0
 public AccountInfo(PasswordFile argPW)
 {
     m_AccountName        = "New Account";
     m_InquiryName        = new string[16];
     m_InquiryValue       = new string[16];
     m_HideFlag           = new bool[16];
     m_obfusPass          = new string[16];
     m_InquiryCount       = 0;
     m_ParentPasswordFile = argPW;
 }
示例#3
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            _ = sender;
            _ = e;

            m_SaveTimer          = new DispatcherTimer();
            m_SaveTimer.Interval = TimeSpan.FromMilliseconds(1000);
            m_SaveTimer.Tick    += OnSaveTimer;
            m_SaveTimer.Start();
            m_LastEditDate = DateTime.UtcNow;

            MODIFIED_LABEL_TEXT        = GlbFunc.GetResourceString("EditEnableToggle_ModifiedText", "Ediable *");
            SAVED_LABEL_TEXT           = GlbFunc.GetResourceString("EditEnableToggle_SavedText", "Ediable");
            EditEnableToggle.OnContent = SAVED_LABEL_TEXT;

            // all of controls are disabled.
            AccountList.Items.Clear();
            InquiryList.Items.Clear();
            m_AccountList_ItemCount = 0;
            SetEdiableState(false);

            // load password file
            if (!await LoadPasswordFile().ConfigureAwait(true))
            {
                // If failed to load password file, all of controls are remain disabled.
                m_PasswordFile             = null;
                EditEnableToggle.IsEnabled = false;
                return;
            }
            AccountList.Items.Clear();
            AccountList.IsEnabled   = true;
            m_AccountList_ItemCount = 0;

            // Insert loaded account information to list
            UpdateAccountList();

            if (m_PasswordFile.GetCount() > 0)
            {
                m_AccountListSelectionFlg = true;
                AccountList.SelectedIndex = 0;
                m_AccountListSelectionFlg = false;
                UpdateInquiryList(0);
            }
            else
            {
                UpdateInquiryList(-1);
            }

            // If account info is empty, default is editable. Others, default is read-only.
            EditEnableToggle.IsOn = (m_PasswordFile.GetCount() == 0);

            Application.Current.Suspending += new SuspendingEventHandler(App_Suspending);
        }
示例#4
0
        public AccountInfo(PasswordFile argPW, AccountInfo cpSrc)
        {
            m_AccountName  = cpSrc.m_AccountName;
            m_InquiryName  = new string[cpSrc.m_InquiryName.Length];
            m_InquiryValue = new string[cpSrc.m_InquiryValue.Length];
            m_HideFlag     = new bool[cpSrc.m_HideFlag.Length];
            m_obfusPass    = new string[cpSrc.m_obfusPass.Length];

            Array.Copy(cpSrc.m_InquiryName, m_InquiryName, cpSrc.m_InquiryName.Length);
            Array.Copy(cpSrc.m_InquiryValue, m_InquiryValue, cpSrc.m_InquiryValue.Length);
            Array.Copy(cpSrc.m_HideFlag, m_HideFlag, cpSrc.m_HideFlag.Length);
            Array.Copy(cpSrc.m_obfusPass, m_obfusPass, cpSrc.m_obfusPass.Length);

            m_InquiryCount       = cpSrc.m_InquiryCount;
            m_ParentPasswordFile = argPW;
        }
示例#5
0
        /// <summary>
        /// Export password file button is clicked.
        /// </summary>
        private async void ExportPasswordFileButton_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;
            _ = e;

            // Load selected password file. If not selected ignore this event
            var r = await LoadSelectedPasswordFile().ConfigureAwait(true);

            PasswordFile pwfile   = r.Item1;
            string       password = r.Item2;

            if (string.IsNullOrEmpty(password) || null == pwfile)
            {
                return;
            }

            // Get output path name of a new plain text file
            FileSavePicker p = new FileSavePicker();

            p.FileTypeChoices.Add(GlbFunc.GetResourceString("TextFileTypeDescription", "Text File"), new List <string>()
            {
                ".txt"
            });
            p.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            StorageFile txtFile = await p.PickSaveFileAsync();

            if (null == txtFile)
            {
                return;
            }

            // Generate string for output
            string plainText = pwfile.BuildStringForOutput(true);

            // write plain text file
            await FileIO.WriteBufferAsync(txtFile, Encoding.GetEncoding( "UTF-8" ).GetBytes( plainText ).AsBuffer());
        }
示例#6
0
        /// <summary>
        /// Import password file button is clicked.
        /// </summary>
        private async void ImportPasswordFileButton_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;
            _ = e;

            // Load selected password file. If not selected ignore this event
            var r = await LoadSelectedPasswordFile().ConfigureAwait(true);

            PasswordFile pwfile   = r.Item1;
            string       password = r.Item2;

            if (string.IsNullOrEmpty(password) || null == pwfile)
            {
                return;
            }

            // get import source file.
            FileOpenPicker p = new FileOpenPicker();

            p.FileTypeFilter.Add(".txt");
            StorageFile txtFile = await p.PickSingleFileAsync();

            if (null == txtFile)
            {
                return;
            }

            // read all of text from file
            string str = await FileIO.ReadTextAsync(txtFile);

            // Initialize password file object
            pwfile.Import(str);

            // Save new password file
            pwfile.Save(password);
        }
示例#7
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);
        }
示例#8
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));
        }