Inheritance: System.Windows.Forms.Form
		internal static string ShowAndRestore(ProtectedString psWord,
			bool bCenterScreen, bool bSetForeground, uint uCharCount, bool? bInitHide)
		{
			IntPtr h = IntPtr.Zero;
			try { h = NativeMethods.GetForegroundWindowHandle(); }
			catch(Exception) { Debug.Assert(false); }

			CharPickerForm dlg = new CharPickerForm();
			dlg.InitEx(psWord, bCenterScreen, bSetForeground, uCharCount, bInitHide);

			DialogResult dr = dlg.ShowDialog();

			ProtectedString ps = dlg.SelectedCharacters;
			string strRet = null;
			if((dr == DialogResult.OK) && (ps != null)) strRet = ps.ReadString();

			UIUtil.DestroyForm(dlg);

			try
			{
				if(h != IntPtr.Zero)
					NativeMethods.EnsureForegroundWindow(h);
			}
			catch(Exception) { Debug.Assert(false); }

			return strRet;
		}
Exemple #2
0
        internal static string ShowAndRestore(ProtectedString psWord,
                                              bool bCenterScreen, bool bSetForeground, uint uCharCount, bool?bInitHide)
        {
            IntPtr h = IntPtr.Zero;

            try { h = NativeMethods.GetForegroundWindowHandle(); }
            catch (Exception) { Debug.Assert(false); }

            CharPickerForm dlg = new CharPickerForm();

            dlg.InitEx(psWord, bCenterScreen, bSetForeground, uCharCount, bInitHide);

            DialogResult dr = dlg.ShowDialog();

            ProtectedString ps     = dlg.SelectedCharacters;
            string          strRet = null;

            if ((dr == DialogResult.OK) && (ps != null))
            {
                strRet = ps.ReadString();
            }

            UIUtil.DestroyForm(dlg);

            try
            {
                if (h != IntPtr.Zero)
                {
                    NativeMethods.EnsureForegroundWindow(h);
                }
            }
            catch (Exception) { Debug.Assert(false); }

            return(strRet);
        }
        private static string ShowCharPickDlg(string strWord, uint uCharCount,
            bool? bInitHide, SprContext ctx, uint uRecursionLevel)
        {
            string strPick = SprEngine.CompileInternal(strWord,
                ctx.WithoutContentTransformations(), uRecursionLevel + 1);

            // No need to show the dialog when there's nothing to pick from
            // (this also prevents the dialog from showing up MaxRecursionDepth
            // times in case of a cyclic {PICKCHARS})
            if(string.IsNullOrEmpty(strPick)) return string.Empty;

            CharPickerForm cpf = new CharPickerForm();
            cpf.InitEx(new ProtectedString(false, strPick), true, true,
                uCharCount, bInitHide);

            string strResult = string.Empty;
            if(cpf.ShowDialog() == DialogResult.OK)
                strResult = cpf.SelectedCharacters.ReadString();

            UIUtil.DestroyForm(cpf);
            return strResult; // Don't transform here
        }
        private static string ReplacePickPwPlaceholder(string str,
            string strPlaceholder, uint uCharCount, SprContext ctx,
            uint uRecursionLevel)
        {
            if(str.IndexOf(strPlaceholder, StrUtil.CaseIgnoreCmp) < 0) return str;

            ProtectedString ps = ctx.Entry.Strings.Get(PwDefs.PasswordField);
            if(ps != null)
            {
                string strPassword = ps.ReadString();

                string strPick = SprEngine.CompileInternal(strPassword,
                    ctx.WithoutContentTransformations(), uRecursionLevel + 1);

                if(!string.IsNullOrEmpty(strPick))
                {
                    ProtectedString psPick = new ProtectedString(false, strPick);
                    CharPickerForm dlg = new CharPickerForm();
                    dlg.InitEx(psPick, true, true, uCharCount, null);

                    if(dlg.ShowDialog() == DialogResult.OK)
                        str = StrUtil.ReplaceCaseInsensitive(str, strPlaceholder,
                            SprEngine.TransformContent(
                            dlg.SelectedCharacters.ReadString(), ctx));
                    UIUtil.DestroyForm(dlg);
                }
            }

            return StrUtil.ReplaceCaseInsensitive(str, strPlaceholder, string.Empty);
        }
Exemple #5
0
		private static string ReplacePickPlaceholder(string str,
			string strPlaceholder, PwEntry pe, PwDatabase pd, SprContentFlags cf,
			uint uCharCount)
		{
			if(str.IndexOf(strPlaceholder, StrUtil.CaseIgnoreCmp) < 0) return str;

			ProtectedString ps = pe.Strings.Get(PwDefs.PasswordField);
			if(ps != null)
			{
				string strPassword = ps.ReadString();
				string strPick = SprEngine.Compile(strPassword, false, pe, pd,
					false, false); // Do not transform content yet

				if(!string.IsNullOrEmpty(strPick))
				{
					ProtectedString psPick = new ProtectedString(false, strPick);
					CharPickerForm dlg = new CharPickerForm();
					dlg.InitEx(psPick, true, true, uCharCount);

					if(dlg.ShowDialog() == DialogResult.OK)
						str = StrUtil.ReplaceCaseInsensitive(str, strPlaceholder,
							SprEngine.TransformContent(dlg.SelectedCharacters.ReadString(), cf));
				}
			}

			return StrUtil.ReplaceCaseInsensitive(str, strPlaceholder, string.Empty);
		}
Exemple #6
0
        private static string ShowCharPickDlg(ProtectedString psWord, uint uCharCount,
            bool? bInitHide)
        {
            CharPickerForm cpf = new CharPickerForm();
            cpf.InitEx(psWord, true, true, uCharCount, bInitHide);

            string strResult = string.Empty;
            if(cpf.ShowDialog() == DialogResult.OK)
                strResult = cpf.SelectedCharacters.ReadString();

            UIUtil.DestroyForm(cpf);
            return strResult;
        }
Exemple #7
0
        public static string FillPlaceholders(string strText, PwEntry pe,
            SprContentFlags cf)
        {
            if(pe == null) return strText;

            string str = strText;

            if(str.ToUpper().IndexOf(@"{PICKPASSWORDCHARS}") >= 0)
            {
                ProtectedString ps = pe.Strings.Get(PwDefs.PasswordField);
                if(ps != null)
                {
                    byte[] pb = ps.ReadUtf8();
                    bool bNotEmpty = (pb.Length > 0);
                    Array.Clear(pb, 0, pb.Length);

                    if(bNotEmpty)
                    {
                        CharPickerForm cpf = new CharPickerForm();
                        cpf.InitEx(ps, true, true);

                        if(cpf.ShowDialog() == DialogResult.OK)
                        {
                            str = StrUtil.ReplaceCaseInsensitive(str, @"{PICKPASSWORDCHARS}",
                                SprEngine.TransformContent(cpf.SelectedCharacters.ReadString(), cf));
                        }
                    }
                }

                str = StrUtil.ReplaceCaseInsensitive(str, @"{PICKPASSWORDCHARS}", string.Empty);
            }

            return str;
        }