예제 #1
0
        private static string GeneratePassword(string strProfile, SprContext ctx)
        {
            PwProfile prf = Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile;

            if (!string.IsNullOrEmpty(strProfile))
            {
                if (strProfile == @"~")
                {
                    prf = PwProfile.DeriveFromPassword(ctx.Entry.Strings.GetSafe(
                                                           PwDefs.PasswordField));
                }
                else
                {
                    List <PwProfile> lPrf = PwGeneratorUtil.GetAllProfiles(false);
                    foreach (PwProfile p in lPrf)
                    {
                        if (strProfile.Equals(p.Name, StrUtil.CaseIgnoreCmp))
                        {
                            prf = p;
                            break;
                        }
                    }
                }
            }

            PwEntry         peCtx = ((ctx != null) ? ctx.Entry : null);
            PwDatabase      pdCtx = ((ctx != null) ? ctx.Database : null);
            ProtectedString ps    = PwGeneratorUtil.GenerateAcceptable(
                prf, null, peCtx, pdCtx);

            return(ps.ReadString());
        }
예제 #2
0
        private static string GeneratePassword(string strProfile, SprContext ctx)
        {
            PwProfile prf = Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile;

            if (!string.IsNullOrEmpty(strProfile))
            {
                if (strProfile == @"~")
                {
                    prf = PwProfile.DeriveFromPassword(ctx.Entry.Strings.GetSafe(
                                                           PwDefs.PasswordField));
                }
                else
                {
                    List <PwProfile> lPrf = PwGeneratorUtil.GetAllProfiles(false);
                    foreach (PwProfile p in lPrf)
                    {
                        if (strProfile.Equals(p.Name, StrUtil.CaseIgnoreCmp))
                        {
                            prf = p;
                            break;
                        }
                    }
                }
            }

            ProtectedString ps;
            PwgError        e = PwGenerator.Generate(out ps, prf, null,
                                                     Program.PwGeneratorPool);

            if ((e != PwgError.Success) || (ps == null))
            {
                return(string.Empty);
            }

            string strGen = ps.ReadString();

            strGen = SprEngine.TransformContent(strGen, ctx);
            return(strGen);
        }