Example #1
0
        private void OnHideCheckedChanged(object sender, EventArgs e)
        {
            if (m_bInitializing)
            {
                return;
            }

            bool bHide = m_cbHide.Checked;

            if (!bHide && !m_bPrgmCheck && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                m_cbHide.Checked = true;
                return;
            }

            m_secPassword.EnableProtection(bHide);
            m_secRepeat.EnableProtection(bHide);

            bool bWasAutoRepeat = Program.Config.UI.RepeatPasswordOnlyWhenHidden;

            if (bHide && !m_bPrgmCheck && bWasAutoRepeat)
            {
                ++m_uBlockUIUpdate;
                byte[] pb = GetPasswordUtf8();
                m_secRepeat.SetPassword(pb);
                MemUtil.ZeroByteArray(pb);
                --m_uBlockUIUpdate;
            }

            UpdateUI();
            if (!m_bPrgmCheck)
            {
                UIUtil.SetFocus(m_tbPassword, m_fParent);
            }
        }
Example #2
0
        private void OnHideCheckedChanged(object sender, EventArgs e)
        {
            if (m_bIgnoreHideCheckEvent)
            {
                return;
            }

            bool bChecked = m_cbHide.Checked;

            foreach (ListViewItem lvi in m_lvColumns.SelectedItems)
            {
                AceColumn c = (lvi.Tag as AceColumn);
                if (c == null)
                {
                    Debug.Assert(false); continue;
                }

                if ((c.Type == AceColumnType.Password) && c.HideWithAsterisks &&
                    !AppPolicy.Try(AppPolicyId.UnhidePasswords))
                {
                    // Do not change c.HideWithAsterisks
                }
                else
                {
                    c.HideWithAsterisks = bChecked;
                }
            }

            UpdateListEx(false);
        }
Example #3
0
 private void toggleOldPassword(object sender, EventArgs e)
 {
     if (AppPolicy.Try(AppPolicyId.UnhidePasswords))
     {
         tbPasswordOld.EnableProtection(cbToggleOldPassword.Checked);
     }
 }
Example #4
0
        public static bool Copy(byte[] pbToCopy, string strFormat, bool bIsEntryInfo)
        {
            Debug.Assert(pbToCopy != null);
            if (pbToCopy == null)
            {
                throw new ArgumentNullException("pbToCopy");
            }

            if (bIsEntryInfo && !AppPolicy.Try(AppPolicyId.CopyToClipboard))
            {
                return(false);
            }

            try
            {
                Clipboard.Clear();

                DataObject doData = CreateProtectedDataObject(strFormat, pbToCopy);
                Clipboard.SetDataObject(doData);

                m_strFormat = strFormat;

                SHA256Managed sha256 = new SHA256Managed();
                m_pbDataHash32 = sha256.ComputeHash(pbToCopy);
            }
            catch (Exception) { Debug.Assert(false); return(false); }

            return(true);
        }
Example #5
0
        public static bool?Synchronize(PwDatabase pwStorage, IUIOperations uiOps,
                                       IOConnectionInfo iocSyncWith, bool bForceSave, Form fParent)
        {
            if (pwStorage == null)
            {
                throw new ArgumentNullException("pwStorage");
            }
            if (!pwStorage.IsOpen)
            {
                return(null);                              // No assert or throw
            }
            if (iocSyncWith == null)
            {
                throw new ArgumentNullException("iocSyncWith");
            }
            if (!AppPolicy.Try(AppPolicyId.Import))
            {
                return(null);
            }

            List <IOConnectionInfo> vConnections = new List <IOConnectionInfo>();

            vConnections.Add(iocSyncWith);

            return(Import(pwStorage, new KeePassKdb2x(), vConnections.ToArray(),
                          true, uiOps, bForceSave, fParent));
        }
Example #6
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider
                                  fileFormat, IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }
            if (fileFormat == null)
            {
                throw new ArgumentNullException("fileFormat");
            }
            if (fileFormat.RequiresFile && (iocOutput == null))
            {
                throw new ArgumentNullException("iocOutput");
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }
            if (!fileFormat.SupportsExport)
            {
                return(false);
            }
            if (!fileFormat.TryBeginExport())
            {
                return(false);
            }

            // bool bExistedAlready = File.Exists(strOutputFile);
            bool bExistedAlready = (fileFormat.RequiresFile ? IOConnection.FileExists(
                                        iocOutput) : false);

            // FileStream fsOut = new FileStream(strOutputFile, FileMode.Create,
            //	FileAccess.Write, FileShare.None);
            Stream sOut = (fileFormat.RequiresFile ? IOConnection.OpenWrite(
                               iocOutput) : null);

            bool bResult = false;

            try { bResult = fileFormat.Export(pwExportInfo, sOut, slLogger); }
            catch (Exception ex) { MessageService.ShowWarning(ex); }

            if (sOut != null)
            {
                sOut.Close();
            }

            if (fileFormat.RequiresFile && (bResult == false) && (bExistedAlready == false))
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch (Exception) { }
            }

            return(bResult);
        }
Example #7
0
        private void OnHideCharsCheckedChanged(object sender, EventArgs e)
        {
            bool bHide = m_cbHideChars.Checked;

            if (!bHide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                m_cbHideChars.Checked = true;
                return;
            }

            m_secWord.EnableProtection(bHide);

            string strHiddenChar = new string(SecureEdit.PasswordChar, 1);

            bool bHideBtns = bHide;

            bHideBtns |= !Program.Config.UI.Hiding.UnhideButtonAlsoUnhidesSource;
            foreach (Button btn in m_lButtons)
            {
                if (bHideBtns)
                {
                    btn.Text = strHiddenChar;
                }
                else
                {
                    btn.Text = new string((char)btn.Tag, 1);
                }
            }
        }
Example #8
0
        public static bool Copy(string strToCopy, bool bIsEntryInfo,
                                PwEntry peEntryInfo, PwDatabase pwReferenceSource)
        {
            Debug.Assert(strToCopy != null);
            if (strToCopy == null)
            {
                throw new ArgumentNullException("strToCopy");
            }

            if (bIsEntryInfo && !AppPolicy.Try(AppPolicyId.CopyToClipboard))
            {
                return(false);
            }

            string strData = SprEngine.Compile(strToCopy, false, peEntryInfo,
                                               pwReferenceSource, false, false);

            try
            {
                Clipboard.Clear();

                DataObject doData = CreateProtectedDataObject(strData);
                Clipboard.SetDataObject(doData);

                m_pbDataHash32 = HashClipboard();
                m_strFormat    = null;
            }
            catch (Exception) { Debug.Assert(false); return(false); }

            return(true);
        }
Example #9
0
        public static bool Export(PwExportInfo pwExportInfo, FileFormatProvider
                                  fileFormat, IOConnectionInfo iocOutput, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }
            if (fileFormat == null)
            {
                throw new ArgumentNullException("fileFormat");
            }
            if (fileFormat.RequiresFile && (iocOutput == null))
            {
                throw new ArgumentNullException("iocOutput");
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }
            if (!fileFormat.SupportsExport)
            {
                return(false);
            }
            if (!fileFormat.TryBeginExport())
            {
                return(false);
            }

            bool bExistedAlready = true;             // No deletion by default
            bool bResult         = false;

            try
            {
                bExistedAlready = (fileFormat.RequiresFile ? IOConnection.FileExists(
                                       iocOutput) : false);
                Stream s = (fileFormat.RequiresFile ? IOConnection.OpenWrite(
                                iocOutput) : null);

                try { bResult = fileFormat.Export(pwExportInfo, s, slLogger); }
                finally { if (s != null)
                          {
                              s.Close();
                          }
                }
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }

            if (fileFormat.RequiresFile && !bResult && !bExistedAlready)
            {
                try { IOConnection.DeleteFile(iocOutput); }
                catch (Exception) { }
            }

            return(bResult);
        }
Example #10
0
        public static bool PerformIntoCurrentWindow(PwEntry pe, PwDatabase pdContext,
                                                    string strSeq)
        {
            if (pe == null)
            {
                Debug.Assert(false); return(false);
            }
            if (!pe.GetAutoTypeEnabled())
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.AutoTypeWithoutContext))
            {
                return(false);
            }

            Thread.Sleep(TargetActivationDelay);

            IntPtr hWnd;
            string strWindow;

            GetForegroundWindowInfo(out hWnd, out strWindow);

            if (!NativeLib.IsUnix())
            {
                if (strWindow == null)
                {
                    Debug.Assert(false); return(false);
                }
            }
            else
            {
                strWindow = string.Empty;
            }

            if (strSeq == null)
            {
                SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin(
                    hWnd, strWindow);

                List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow,
                                                           pdContext, evQueries.EventID);

                GetSequencesForWindowEnd(evQueries);

                if (lSeq.Count == 0)
                {
                    strSeq = pe.GetAutoTypeSequence();
                }
                else
                {
                    strSeq = lSeq[0];
                }
            }

            AutoTypeCtx ctx = new AutoTypeCtx(strSeq, pe, pdContext);

            return(AutoType.PerformInternal(ctx, strWindow));
        }
        public bool InitEx(EcasTriggerSystem triggers, ImageList ilIcons)
        {
            m_triggersInOut = triggers;
            m_triggers      = triggers.CloneDeep();

            m_ilIcons = ilIcons;

            return(AppPolicy.Try(AppPolicyId.EditTriggers));
        }
Example #12
0
 private void mToggleHidden_CheckedChanged(object sender, EventArgs e)
 {
     if (!mToggleHidden.Checked && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
     {
         mToggleHidden.Checked = true;
         return;
     }
     mSecureEdit.EnableProtection(mToggleHidden.Checked);
 }
Example #13
0
        public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                FileFormatProvider ffp = dlg.ResultFormat;
                if (ffp == null)
                {
                    Debug.Assert(false); return(false);
                }
                if (ffp.RequiresFile)
                {
                    if (dlg.ResultFiles.Length != 1)
                    {
                        Debug.Assert(false); return(false);
                    }
                    if (dlg.ResultFiles[0] == null)
                    {
                        Debug.Assert(false); return(false);
                    }
                    if (dlg.ResultFiles[0].Length == 0)
                    {
                        Debug.Assert(false); return(false);
                    }
                }

                Application.DoEvents();                 // Redraw parent window

                IOConnectionInfo iocOutput = (ffp.RequiresFile ? IOConnectionInfo.FromPath(
                                                  dlg.ResultFiles[0]) : null);

                try
                {
                    return(Export(pwExportInfo, dlg.ResultFormat, iocOutput, slLogger));
                }
                catch (Exception ex) { MessageService.ShowWarning(ex); }
            }

            return(false);
        }
Example #14
0
            public bool OTPDB_ChangePassword(bool change)
            {
                List <string> lMsg = new List <string>();

                try
                {
                    if (!Valid || !OTPDB_Exists || !OTPDB_Opened)
                    {
                        return(false);
                    }
                    if (change && !AppPolicy.Try(AppPolicyId.ChangeMasterKey))
                    {
                        return(false);
                    }

                    if (change && !AppPolicy.Current.ChangeMasterKeyNoKey && !ReAskKey())
                    {
                        lMsg.Add("Invalid masterkey entered");
                        return(false);
                    }
                    if (!change)
                    {
                        Tools.ShowInfo(PluginTranslate.OTP_CreateDB_PWHint);
                    }

                    bool bCancel;
                    KeySources_Clear();
                    AceKeyAssoc aka_old = KeySources_Load();
                    OTPDB.MasterKey = OTPDB_RequestPassword(true, out bCancel);
                    KeySources_Clear();
                    if (bCancel)
                    {
                        lMsg.Add("Password change cancelled by user");
                        return(false);
                    }
                    else
                    {
                        lMsg.Add("Password change done");
                    }

                    //Store key sources to reread them in the proper format
                    //SetKeySources won't do anything if KeePass config does not allow key sources to be remembered
                    Program.Config.Defaults.SetKeySources(EmptyIOC, OTPDB.MasterKey);
                    AceKeyAssoc aka_new = Program.Config.Defaults.GetKeySources(EmptyIOC);
                    KeySources_Clear();

                    FlagChanged(false);
                    FlagChanged(true);
                    if (KeySources_Equal(aka_old, aka_new))
                    {
                        return(true);
                    }
                    KeySources_Save(aka_new);
                    return(true);
                }
                finally { PluginDebug.AddInfo("OTP DB - change password", 0, lMsg.ToArray()); }
            }
Example #15
0
        public static bool Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return(false);
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            bool bResult = false;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                FileFormatProvider ffp = dlg.ResultFormat;
                if (ffp == null)
                {
                    Debug.Assert(false); goto ExpZRet;
                }
                if (ffp.RequiresFile)
                {
                    if (dlg.ResultFiles.Length != 1)
                    {
                        Debug.Assert(false); goto ExpZRet;
                    }
                    if (dlg.ResultFiles[0] == null)
                    {
                        Debug.Assert(false); goto ExpZRet;
                    }
                    if (dlg.ResultFiles[0].Length == 0)
                    {
                        Debug.Assert(false); goto ExpZRet;
                    }
                }

                IOConnectionInfo iocOutput = (ffp.RequiresFile ? IOConnectionInfo.FromPath(
                                                  dlg.ResultFiles[0]) : null);

                Application.DoEvents();                 // Redraw parent window
                bResult = Export(pwExportInfo, ffp, iocOutput, slLogger);
            }

ExpZRet:
            UIUtil.DestroyForm(dlg);
            return(bResult);
        }
Example #16
0
        public static bool PerformIntoCurrentWindow(PwEntry pe, PwDatabase pdContext)
        {
            if (pe == null)
            {
                Debug.Assert(false); return(false);
            }
            if (!pe.GetAutoTypeEnabled())
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.AutoTypeWithoutContext))
            {
                return(false);
            }

            IntPtr hWnd;
            string strWindow;

            try
            {
                NativeMethods.GetForegroundWindowInfo(out hWnd, out strWindow, true);
            }
            catch (Exception) { hWnd = IntPtr.Zero; strWindow = null; }

            if (!KeePassLib.Native.NativeLib.IsUnix())
            {
                if (strWindow == null)
                {
                    Debug.Assert(false); return(false);
                }
            }
            else
            {
                strWindow = string.Empty;
            }

            Thread.Sleep(100);

            SequenceQueriesEventArgs evQueries = GetSequencesForWindowBegin(
                hWnd, strWindow);

            List <string> lSeq = GetSequencesForWindow(pe, hWnd, strWindow,
                                                       pdContext, evQueries.EventID);

            GetSequencesForWindowEnd(evQueries);

            if (lSeq.Count == 0)
            {
                lSeq.Add(pe.GetAutoTypeSequence());
            }

            AutoTypeCtx ctx = new AutoTypeCtx(lSeq[0], pe, pdContext);

            return(AutoType.PerformInternal(ctx, strWindow));
        }
Example #17
0
        private void OnCheckedHidePassword(object sender, EventArgs e)
        {
            bool bHide = m_cbHidePassword.Checked;

            if (!bHide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                m_cbHidePassword.Checked = true;
                return;
            }

            m_secPassword.EnableProtection(bHide);
        }
Example #18
0
        public static void Export(PwExportInfo pwExportInfo, IStatusLogger slLogger)
        {
            if (pwExportInfo == null)
            {
                throw new ArgumentNullException("pwExportInfo");
            }
            if (pwExportInfo.DataGroup == null)
            {
                throw new ArgumentException();
            }

            if (!AppPolicy.Try(AppPolicyId.Export))
            {
                return;
            }

            ExchangeDataForm dlg = new ExchangeDataForm();

            dlg.InitEx(true, pwExportInfo.ContextDatabase, pwExportInfo.DataGroup);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (dlg.ResultFormat == null)
                {
                    Debug.Assert(false); return;
                }
                if (dlg.ResultFiles.Length != 1)
                {
                    Debug.Assert(false); return;
                }
                if (dlg.ResultFiles[0] == null)
                {
                    Debug.Assert(false); return;
                }
                if (dlg.ResultFiles[0].Length == 0)
                {
                    Debug.Assert(false); return;
                }

                Application.DoEvents();                 // Redraw parent window

                try
                {
                    PerformExport(pwExportInfo, dlg.ResultFormat, dlg.ResultFiles[0],
                                  slLogger);
                }
                catch (Exception ex)
                {
                    MessageService.ShowWarning(ex);
                }
            }
        }
Example #19
0
        public static bool?Synchronize(PwDatabase pwStorage, IUIOperations uiOps,
                                       bool bOpenFromUrl, Form fParent)
        {
            if (pwStorage == null)
            {
                throw new ArgumentNullException("pwStorage");
            }
            if (!pwStorage.IsOpen)
            {
                return(null);
            }
            if (!AppPolicy.Try(AppPolicyId.Import))
            {
                return(null);
            }

            List <IOConnectionInfo> vConnections = new List <IOConnectionInfo>();

            if (bOpenFromUrl == false)
            {
                OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.Synchronize,
                                                                   UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.FileExt,
                                                                                               KPRes.KdbxFiles, true), 1, null, true,
                                                                   AppDefs.FileDialogContext.Sync);

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return(null);
                }

                foreach (string strSelFile in ofd.FileNames)
                {
                    vConnections.Add(IOConnectionInfo.FromPath(strSelFile));
                }
            }
            else             // Open URL
            {
                IOConnectionForm iocf = new IOConnectionForm();
                iocf.InitEx(false, null, true, true);

                if (UIUtil.ShowDialogNotValue(iocf, DialogResult.OK))
                {
                    return(null);
                }

                vConnections.Add(iocf.IOConnectionInfo);
                UIUtil.DestroyForm(iocf);
            }

            return(Import(pwStorage, new KeePassKdb2x(), vConnections.ToArray(),
                          true, uiOps, false, fParent));
        }
Example #20
0
        private void OnCheckedHidePassword(object sender, EventArgs e)
        {
            bool bHide = m_cbHidePassword.Checked;

            if (!bHide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                m_cbHidePassword.Checked = true;
                return;
            }

            SetHidePassword(bHide, false);
            m_tbPassword.Focus();
        }
Example #21
0
        private static bool Execute(string strSeq, PwEntry pweData)
        {
            Debug.Assert(strSeq != null); if (strSeq == null)
            {
                return(false);
            }
            Debug.Assert(pweData != null); if (pweData == null)
            {
                return(false);
            }

            if (!pweData.AutoType.Enabled)
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.AutoType))
            {
                return(false);
            }

            PwDatabase pwDatabase = null;

            try { pwDatabase = Program.MainForm.PluginHost.Database; }
            catch (Exception) { pwDatabase = null; }

            string strSend = SprEngine.Compile(strSeq, true, pweData,
                                               pwDatabase, true, false);

            string strError = ValidateAutoTypeSequence(strSend);

            if (strError != null)
            {
                MessageService.ShowWarning(strError);
                return(false);
            }

            bool bObfuscate = (pweData.AutoType.ObfuscationOptions !=
                               AutoTypeObfuscationOptions.None);

            Application.DoEvents();

            try { SendInputEx.SendKeysWait(strSend, bObfuscate); }
            catch (Exception excpAT)
            {
                MessageService.ShowWarning(excpAT);
            }

            return(true);
        }
Example #22
0
        public static bool Synchronize(PwDatabase pwStorage, IUIOperations uiOps,
                                       bool bOpenFromUrl)
        {
            if (pwStorage == null)
            {
                throw new ArgumentNullException("pwStorage");
            }
            if (!pwStorage.IsOpen)
            {
                return(false);
            }
            if (!AppPolicy.Try(AppPolicyId.Import))
            {
                return(false);
            }

            List <IOConnectionInfo> vConnections = new List <IOConnectionInfo>();

            if (bOpenFromUrl == false)
            {
                OpenFileDialog ofd = UIUtil.CreateOpenFileDialog(KPRes.Synchronize,
                                                                 UIUtil.CreateFileTypeFilter(null, null, true), 1, null, true, true);

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return(true);
                }

                foreach (string strSelFile in ofd.FileNames)
                {
                    vConnections.Add(IOConnectionInfo.FromPath(strSelFile));
                }
            }
            else             // Open URL
            {
                IOConnectionForm iocf = new IOConnectionForm();
                iocf.InitEx(false, new IOConnectionInfo(), false, true);

                if (iocf.ShowDialog() != DialogResult.OK)
                {
                    return(true);
                }

                vConnections.Add(iocf.IOConnectionInfo);
            }

            return(PerformImport(pwStorage, new KeePassKdb2x(), vConnections.ToArray(),
                                 true, uiOps, false));
        }
Example #23
0
        public static bool?Import(PwDatabase pwStorage, out bool bAppendedToRootOnly,
                                  Form fParent)
        {
            bAppendedToRootOnly = false;

            if (pwStorage == null)
            {
                throw new ArgumentNullException("pwStorage");
            }
            if (!pwStorage.IsOpen)
            {
                return(null);
            }
            if (!AppPolicy.Try(AppPolicyId.Import))
            {
                return(null);
            }

            ExchangeDataForm dlgFmt = new ExchangeDataForm();

            dlgFmt.InitEx(false, pwStorage, pwStorage.RootGroup);

            if (UIUtil.ShowDialogNotValue(dlgFmt, DialogResult.OK))
            {
                return(null);
            }

            Debug.Assert(dlgFmt.ResultFormat != null);
            if (dlgFmt.ResultFormat == null)
            {
                MessageService.ShowWarning(KPRes.ImportFailed);
                UIUtil.DestroyForm(dlgFmt);
                return(false);
            }

            bAppendedToRootOnly = dlgFmt.ResultFormat.ImportAppendsToRootGroupOnly;
            FileFormatProvider ffp = dlgFmt.ResultFormat;

            List <IOConnectionInfo> lConnections = new List <IOConnectionInfo>();

            foreach (string strSelFile in dlgFmt.ResultFiles)
            {
                lConnections.Add(IOConnectionInfo.FromPath(strSelFile));
            }

            UIUtil.DestroyForm(dlgFmt);
            return(Import(pwStorage, ffp, lConnections.ToArray(),
                          false, null, false, fParent));
        }
Example #24
0
        public static bool?Import(PwDatabase pd, FileFormatProvider fmtImp,
                                  IOConnectionInfo iocImp, PwMergeMethod mm, CompositeKey cmpKey)
        {
            if (pd == null)
            {
                Debug.Assert(false); return(false);
            }
            if (fmtImp == null)
            {
                Debug.Assert(false); return(false);
            }
            if (iocImp == null)
            {
                Debug.Assert(false); return(false);
            }
            if (cmpKey == null)
            {
                cmpKey = new CompositeKey();
            }

            if (!AppPolicy.Try(AppPolicyId.Import))
            {
                return(false);
            }
            if (!fmtImp.TryBeginImport())
            {
                return(false);
            }

            PwDatabase pdImp = new PwDatabase();

            pdImp.New(new IOConnectionInfo(), cmpKey);
            pdImp.MemoryProtection = pd.MemoryProtection.CloneDeep();

            Stream s = IOConnection.OpenRead(iocImp);

            if (s == null)
            {
                throw new FileNotFoundException(iocImp.GetDisplayName() +
                                                MessageService.NewLine + KPRes.FileNotFoundError);
            }

            try { fmtImp.Import(pdImp, s, null); }
            finally { s.Close(); }

            pd.MergeIn(pdImp, mm);
            return(true);
        }
    private void hidePasswordCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        bool hide = hidePasswordCheckBox.Checked;

        if (!hide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
        {
            hidePasswordCheckBox.Checked = true;
            return;
        }

        secureTextBox.EnableProtection(hide);

        if (!_initializing)
        {
            UIUtil.SetFocus(secureTextBox, this);
        }
    }
Example #26
0
        private void OnCheckedHidePassword(object sender, EventArgs e)
        {
            bool bHide = m_cbHidePassword.Checked;

            if (!bHide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                m_cbHidePassword.Checked = true;
                return;
            }

            m_tbPassword.EnableProtection(bHide);

            if (!m_bInitializing)
            {
                UIUtil.SetFocus(m_tbPassword, this);
            }
        }
Example #27
0
        private void OnCheckedHideKey(object sender, EventArgs e)
        {
            var hide = hideKeyCheckBox.Checked;

            if (!hide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                hideKeyCheckBox.Checked = true;
                return;
            }

            secureEdit.EnableProtection(hide);

            if (!initializing)
            {
                UIUtil.SetFocus(keyTextBox, this);
            }
        }
        private void OnCheckedHideKey(object sender, EventArgs e)
        {
            bool hide = hideKeyCheckBox.Checked;

            if (!hide && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                hideKeyCheckBox.Checked = true;
                return;
            }

            keyTextBox.UseSystemPasswordChar = hide;

            if (!m_bInitializing)
            {
                UIUtil.SetFocus(keyTextBox, this);
            }
        }
Example #29
0
        private void OnHidePasswordCheckedChanged(object sender, EventArgs e)
        {
            bool bAuto = (m_uUIAutoBlocked == 0);
            bool bHide = m_cbHidePassword.Checked;

            if (!bHide && bAuto && !AppPolicy.Try(AppPolicyId.UnhidePasswords))
            {
                UIUtil.SetChecked(m_cbHidePassword, true);
                return;
            }

            m_tbPassword.EnableProtection(bHide);

            if (bAuto)
            {
                UIUtil.SetFocus(m_tbPassword, this);
            }
        }
Example #30
0
        // Start of modification by B.L

        //Shamir Synchronize
        public static bool?ShamirSynchronize(PwDatabase pwStorage, IUIOperations uiOps,
                                             bool bOpenFromUrl, Form fParent, List <string> paths)
        {
            if (pwStorage == null)
            {
                throw new ArgumentNullException("pwStorage");
            }
            if (!pwStorage.IsOpen)
            {
                return(null);
            }
            if (!AppPolicy.Try(AppPolicyId.Import))
            {
                return(null);
            }

            List <IOConnectionInfo> vConnections = new List <IOConnectionInfo>();

            if (bOpenFromUrl == false)
            {
                foreach (string s in paths)
                {
                    vConnections.Add(IOConnectionInfo.FromPath(s));
                }
            }
            else // Open URL
            {
                IOConnectionForm iocf = new IOConnectionForm();
                iocf.InitEx(false, null, true, true);

                if (UIUtil.ShowDialogNotValue(iocf, DialogResult.OK))
                {
                    return(null);
                }

                vConnections.Add(iocf.IOConnectionInfo);
                UIUtil.DestroyForm(iocf);
            }

            return(Import(pwStorage, new KeePassKdb2x(), vConnections.ToArray(),
                          true, uiOps, false, fParent));
        }