InitEx() public method

public InitEx ( string strTitle, string strDesc, string strLongDesc, Image imgIcon, string strDefaultText, string vSelectable ) : void
strTitle string
strDesc string
strLongDesc string
imgIcon Image
strDefaultText string
vSelectable string
return void
Exemplo n.º 1
0
        private void OnBtnProfileSave(object sender, EventArgs e)
        {
            List<string> lNames = new List<string>();
            lNames.Add(AutoGeneratedMeta);
            foreach(PwProfile pwExisting in Program.Config.PasswordGenerator.UserProfiles)
                lNames.Add(pwExisting.Name);

            SingleLineEditForm slef = new SingleLineEditForm();
            slef.InitEx(KPRes.GenProfileSave, KPRes.GenProfileSaveDesc,
                KPRes.GenProfileSaveDescLong, Properties.Resources.B48x48_KGPG_Gen,
                string.Empty, lNames.ToArray());

            if(slef.ShowDialog() == DialogResult.OK)
            {
                string strProfile = slef.ResultString;

                PwProfile pwCurrent = GetGenerationOptions();
                pwCurrent.Name = strProfile;

                if(strProfile.Equals(CustomMeta) || strProfile.Equals(DeriveFromPrevious) ||
                    (strProfile.Length == 0) || PwGeneratorUtil.IsBuiltInProfile(strProfile))
                {
                    MessageService.ShowWarning(KPRes.FieldNameInvalid);
                }
                else if(strProfile == AutoGeneratedMeta)
                {
                    pwCurrent.Name = string.Empty;
                    Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile = pwCurrent;
                    m_cmbProfiles.SelectedIndex = m_cmbProfiles.FindString(AutoGeneratedMeta);
                }
                else
                {
                    List<PwProfile> lUser = Program.Config.PasswordGenerator.UserProfiles;

                    bool bExists = false;
                    for(int i = 0; i < lUser.Count; ++i)
                    {
                        if(lUser[i].Name.Equals(strProfile, StrUtil.CaseIgnoreCmp))
                        {
                            lUser[i] = pwCurrent;

                            for(int j = 0; j < m_cmbProfiles.Items.Count; ++j)
                            {
                                if(m_cmbProfiles.Items[j].ToString().Equals(strProfile,
                                    StrUtil.CaseIgnoreCmp))
                                {
                                    m_bBlockUIUpdate = true;
                                    m_cmbProfiles.Items[j] = strProfile; // Fix case
                                    m_bBlockUIUpdate = false;
                                    m_cmbProfiles.SelectedIndex = j;
                                    bExists = true;
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    if(!bExists)
                    {
                        m_bBlockUIUpdate = true;

                        List<PwProfile> lAll = PwGeneratorUtil.GetAllProfiles(false);
                        for(int c = 0; c < lAll.Count; ++c)
                            m_cmbProfiles.Items.RemoveAt(m_cmbProfiles.Items.Count - 1);

                        lUser.Add(pwCurrent);

                        int iNewSel = 0;
                        foreach(PwProfile pwAdd in PwGeneratorUtil.GetAllProfiles(true))
                        {
                            m_cmbProfiles.Items.Add(pwAdd.Name);
                            if(pwAdd.Name == strProfile)
                                iNewSel = m_cmbProfiles.Items.Count - 1;
                        }

                        m_bBlockUIUpdate = false;
                        m_cmbProfiles.SelectedIndex = iNewSel;
                    }
                }
            }
            UIUtil.DestroyForm(slef);

            EnableControlsEx(false);
        }
Exemplo n.º 2
0
		public override void Import(PwDatabase pwStorage, Stream sInput,
			IStatusLogger slLogger)
		{
			slLogger.SetText("> Spamex.com...", LogStatusType.Info);

			SingleLineEditForm dlgUser = new SingleLineEditForm();
			dlgUser.InitEx("Spamex.com", KPRes.WebSiteLogin + " - " + KPRes.UserName,
				KPRes.UserNamePrompt, KeePass.Properties.Resources.B48x48_WWW,
				string.Empty, null);
			if(dlgUser.ShowDialog() != DialogResult.OK) return;

			SingleLineEditForm dlgPassword = new SingleLineEditForm();
			dlgPassword.InitEx("Spamex.com", KPRes.WebSiteLogin + " - " + KPRes.Password,
				KPRes.PasswordPrompt, KeePass.Properties.Resources.B48x48_WWW,
				string.Empty, null);
			if(dlgPassword.ShowDialog() != DialogResult.OK) return;

			RemoteCertificateValidationCallback pPrevCertCb =
				ServicePointManager.ServerCertificateValidationCallback;

			ServicePointManager.ServerCertificateValidationCallback =
				delegate(object sender, X509Certificate certificate, X509Chain chain,
					SslPolicyErrors sslPolicyErrors)
				{
					return true;
				};

			try
			{
				slLogger.SetText(KPRes.ImportingStatusMsg, LogStatusType.Info);

				string strUser = dlgUser.ResultString; ;
				string strPassword = dlgPassword.ResultString;

				string strPostData = @"toollogin=&MetaDomain=&LoginEmail=" +
					strUser + @"&LoginPassword="******"&Remember=1";

				List<KeyValuePair<string, string>> vCookies;
				string strMain = NetUtil.WebPageLogin(new Uri(UrlLoginPage),
					strPostData, out vCookies);

				if(strMain.IndexOf("Welcome <b>" + strUser + "</b>") < 0)
				{
					MessageService.ShowWarning(KPRes.InvalidUserPassword);
					return;
				}

				string strIndexPage = NetUtil.WebPageGetWithCookies(new Uri(UrlIndexPage),
					vCookies, UrlDomain);

				ImportIndex(pwStorage, strIndexPage, vCookies, slLogger);

				int nOffset = 0;
				List<string> vSubPages = new List<string>();
				while(true)
				{
					string strLink = StrUtil.GetStringBetween(strIndexPage, nOffset,
						StrTabLinksStart, StrTabLinksEnd, out nOffset);
					++nOffset;

					if(strLink.Length == 0) break;

					if(!strLink.StartsWith(StrTabLinkUrl)) continue;
					if(vSubPages.IndexOf(strLink) >= 0) continue;

					vSubPages.Add(strLink);

					string strSubPage = NetUtil.WebPageGetWithCookies(new Uri(
						UrlBase + strLink), vCookies, UrlDomain);

					ImportIndex(pwStorage, strSubPage, vCookies, slLogger);
				}
			}
			catch
			{
				ServicePointManager.ServerCertificateValidationCallback = pPrevCertCb;
				throw;
			}

			ServicePointManager.ServerCertificateValidationCallback = pPrevCertCb;
		}
Exemplo n.º 3
0
		private void OnAddEntryTag(object sender, DynamicMenuEventArgs e)
		{
			string strTag = (e.Tag as string);
			if(strTag == null) { Debug.Assert(false); return; }

			if(strTag.Length == 0)
			{
				SingleLineEditForm dlg = new SingleLineEditForm();
				dlg.InitEx(KPRes.TagNew, KPRes.TagAddNew, KPRes.Name + ":",
					Properties.Resources.B48x48_KMag, string.Empty, null);

				if(UIUtil.ShowDialogNotValue(dlg, DialogResult.OK)) return;
				strTag = dlg.ResultString;
				UIUtil.DestroyForm(dlg);
			}

			if(!string.IsNullOrEmpty(strTag))
				AddOrRemoveTagsToFromSelectedEntries(strTag, true);
		}
Exemplo n.º 4
0
        private void OnToolsGeneratePasswordList(object sender, EventArgs e)
        {
            PwDatabase pwDb = m_docMgr.ActiveDatabase;
            if(!pwDb.IsOpen) return;

            PwGeneratorForm pgf = new PwGeneratorForm();

            pgf.InitEx(null, true, IsTrayed());
            if(pgf.ShowDialog() == DialogResult.OK)
            {
                PwGroup pg = GetSelectedGroup();
                if(pg == null) pg = pwDb.RootGroup;

                SingleLineEditForm dlgCount = new SingleLineEditForm();
                dlgCount.InitEx(KPRes.GenerateCount, KPRes.GenerateCountDesc,
                    KPRes.GenerateCountLongDesc, Properties.Resources.B48x48_KGPG_Gen,
                    string.Empty, null);
                if(dlgCount.ShowDialog() == DialogResult.OK)
                {
                    uint uCount;
                    if(!uint.TryParse(dlgCount.ResultString, out uCount))
                        uCount = 1;

                    byte[] pbAdditionalEntropy = EntropyForm.CollectEntropyIfEnabled(
                        pgf.SelectedProfile);

                    for(uint i = 0; i < uCount; ++i)
                    {
                        PwEntry pe = new PwEntry(true, true);
                        pg.AddEntry(pe, true);

                        ProtectedString psNew = new ProtectedString(pwDb.MemoryProtection.ProtectPassword);
                        PwGenerator.Generate(psNew, pgf.SelectedProfile,
                            pbAdditionalEntropy, Program.PwGeneratorPool);
                        pe.Strings.Set(PwDefs.PasswordField, psNew);
                    }

                    UpdateUI(false, null, false, null, true, null, true);
                }
                UIUtil.DestroyForm(dlgCount);
            }
            UIUtil.DestroyForm(pgf);
        }
Exemplo n.º 5
0
        public override void Import(PwDatabase pwStorage, Stream sInput,
            IStatusLogger slLogger)
        {
            SingleLineEditForm dlg = new SingleLineEditForm();
            dlg.InitEx(KPRes.Password, KPRes.Import + ": " + this.FormatName,
                KPRes.PasswordPrompt, Properties.Resources.B48x48_KGPG_Key2,
                string.Empty, null);
            if(UIUtil.ShowDialogNotValue(dlg, DialogResult.OK)) return;
            string strPassword = dlg.ResultString;
            UIUtil.DestroyForm(dlg);

            byte[] pbPassword = Encoding.Default.GetBytes(strPassword);

            BinaryReader br = new BinaryReader(sInput, Encoding.Default);

            ushort usFileVersion = br.ReadUInt16();
            if(usFileVersion != 0x0100)
                throw new Exception(KLRes.FileVersionUnsupported);

            uint uEntries = br.ReadUInt32();
            uint uKeySize = br.ReadUInt32();
            Debug.Assert(uKeySize == 50); // It's a constant

            byte btKeyArrayLen = br.ReadByte();
            byte[] pbKey = br.ReadBytes(btKeyArrayLen);

            byte btValidArrayLen = br.ReadByte();
            byte[] pbValid = br.ReadBytes(btValidArrayLen);

            if(pbPassword.Length > 0)
            {
                MangleSetKey(pbPassword);
                MangleDecode(pbKey);
            }

            MangleSetKey(pbKey);
            MangleDecode(pbValid);
            string strValid = Encoding.Default.GetString(pbValid);
            if(strValid != "aacaaaadaaeabaacyuioqaqqaaaaaertaaajkadaadaaxywqea")
                throw new Exception(KLRes.InvalidCompositeKey);

            for(uint uEntry = 0; uEntry < uEntries; ++uEntry)
            {
                PwEntry pe = new PwEntry(true, true);
                pwStorage.RootGroup.AddEntry(pe, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
                    pwStorage.MemoryProtection.ProtectTitle, ReadString(br)));
                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
                    pwStorage.MemoryProtection.ProtectUserName, ReadString(br)));
                pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
                    pwStorage.MemoryProtection.ProtectPassword, ReadString(br)));
                pe.Strings.Set("Hint", new ProtectedString(false, ReadString(br)));
                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
                    pwStorage.MemoryProtection.ProtectNotes, ReadString(br)));
                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
                    pwStorage.MemoryProtection.ProtectUrl, ReadString(br)));
            }

            br.Close();
            sInput.Close();
        }
Exemplo n.º 6
0
        private void OnBtnProfileSave(object sender, EventArgs e)
        {
            List <string> lNames = new List <string>();

            lNames.Add(AutoGeneratedMeta);
            foreach (PwProfile pwExisting in Program.Config.PasswordGenerator.UserProfiles)
            {
                lNames.Add(pwExisting.Name);
            }

            SingleLineEditForm slef = new SingleLineEditForm();

            slef.InitEx(KPRes.GenProfileSave, KPRes.GenProfileSaveDesc,
                        KPRes.GenProfileSaveDescLong, Properties.Resources.B48x48_KGPG_Gen,
                        string.Empty, lNames.ToArray());

            if (slef.ShowDialog() == DialogResult.OK)
            {
                string strProfile = slef.ResultString;

                PwProfile pwCurrent = GetGenerationOptions();
                pwCurrent.Name = strProfile;

                if (strProfile.Equals(CustomMeta) || strProfile.Equals(DeriveFromPrevious) ||
                    (strProfile.Length == 0) || PwGeneratorUtil.IsBuiltInProfile(strProfile))
                {
                    MessageService.ShowWarning(KPRes.FieldNameInvalid);
                }
                else if (strProfile == AutoGeneratedMeta)
                {
                    pwCurrent.Name = string.Empty;
                    Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile = pwCurrent;
                    m_cmbProfiles.SelectedIndex = m_cmbProfiles.FindString(AutoGeneratedMeta);
                }
                else
                {
                    List <PwProfile> lUser = Program.Config.PasswordGenerator.UserProfiles;

                    bool bExists = false;
                    for (int i = 0; i < lUser.Count; ++i)
                    {
                        if (lUser[i].Name.Equals(strProfile, StrUtil.CaseIgnoreCmp))
                        {
                            lUser[i] = pwCurrent;

                            for (int j = 0; j < m_cmbProfiles.Items.Count; ++j)
                            {
                                if (m_cmbProfiles.Items[j].ToString().Equals(strProfile,
                                                                             StrUtil.CaseIgnoreCmp))
                                {
                                    m_bBlockUIUpdate            = true;
                                    m_cmbProfiles.Items[j]      = strProfile;                                // Fix case
                                    m_bBlockUIUpdate            = false;
                                    m_cmbProfiles.SelectedIndex = j;
                                    bExists = true;
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    if (!bExists)
                    {
                        m_bBlockUIUpdate = true;

                        List <PwProfile> lAll = PwGeneratorUtil.GetAllProfiles(false);
                        for (int c = 0; c < lAll.Count; ++c)
                        {
                            m_cmbProfiles.Items.RemoveAt(m_cmbProfiles.Items.Count - 1);
                        }

                        lUser.Add(pwCurrent);

                        int iNewSel = 0;
                        foreach (PwProfile pwAdd in PwGeneratorUtil.GetAllProfiles(true))
                        {
                            m_cmbProfiles.Items.Add(pwAdd.Name);
                            if (pwAdd.Name == strProfile)
                            {
                                iNewSel = m_cmbProfiles.Items.Count - 1;
                            }
                        }

                        m_bBlockUIUpdate            = false;
                        m_cmbProfiles.SelectedIndex = iNewSel;
                    }
                }
            }
            UIUtil.DestroyForm(slef);

            EnableControlsEx(false);
        }
Exemplo n.º 7
0
        private void OnBtnProfileSave(object sender, EventArgs e)
        {
            List<string> lNames = new List<string>();
            lNames.Add(AutoGeneratedMeta);
            foreach(PwProfile pwExisting in Program.Config.PasswordGenerator.UserProfiles)
                lNames.Add(pwExisting.Name);

            SingleLineEditForm slef = new SingleLineEditForm();
            slef.InitEx(KPRes.GenProfileSave, KPRes.GenProfileSaveDesc,
                KPRes.GenProfileSaveDescLong, Properties.Resources.B48x48_KGPG_Gen,
                string.Empty, lNames.ToArray());

            if(slef.ShowDialog() == DialogResult.OK)
            {
                string strProfile = slef.ResultString;

                PwProfile pwCurrent = GetGenerationOptions();
                pwCurrent.Name = strProfile;

                if(strProfile.Equals(CustomMeta) || strProfile.Equals(DeriveFromPrevious) ||
                    (strProfile.Length == 0))
                {
                    MessageService.ShowWarning(KPRes.FieldNameInvalid);
                }
                else if(strProfile == AutoGeneratedMeta)
                {
                    pwCurrent.Name = string.Empty;
                    Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile = pwCurrent;
                    m_cmbProfiles.SelectedIndex = m_cmbProfiles.FindString(AutoGeneratedMeta);
                }
                else
                {
                    bool bExists = false;
                    for(int i = 0; i < Program.Config.PasswordGenerator.UserProfiles.Count; ++i)
                    {
                        if(Program.Config.PasswordGenerator.UserProfiles[i].Name == strProfile)
                        {
                            Program.Config.PasswordGenerator.UserProfiles[i] = pwCurrent;
                            m_cmbProfiles.SelectedIndex = m_cmbProfiles.FindString(strProfile);
                            bExists = true;
                        }
                    }

                    if(bExists == false)
                    {
                        Program.Config.PasswordGenerator.UserProfiles.Add(pwCurrent);
                        m_cmbProfiles.Items.Add(strProfile);
                        m_cmbProfiles.SelectedIndex = m_cmbProfiles.Items.Count - 1;
                    }
                }
            }
            UIUtil.DestroyForm(slef);

            EnableControlsEx(false);
        }