Esempio n. 1
0
        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);
                    string          strPicked = (CharPickerForm.ShowAndRestore(psPick,
                                                                               true, true, uCharCount, null) ?? string.Empty);

                    str = StrUtil.ReplaceCaseInsensitive(str, strPlaceholder,
                                                         SprEngine.TransformContent(strPicked, ctx));
                }
            }

            return(StrUtil.ReplaceCaseInsensitive(str, strPlaceholder, string.Empty));
        }
Esempio n. 2
0
        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
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        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);
            }

            ProtectedString psWord    = new ProtectedString(false, strPick);
            string          strPicked = CharPickerForm.ShowAndRestore(psWord,
                                                                      true, true, uCharCount, bInitHide);

            return(strPicked ?? string.Empty);              // Don't transform here
        }
Esempio n. 5
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);
        }