public Condition(string usedOperator, string firstOperand, string secondOperand) : this()
 {
     UsedOperator  = usedOperator;
     FirstOperand  = firstOperand;
     SecondOperand = secondOperand;
     HashingEx.Hashing.GetSha1Hash(DateTime.Now.ToString() + " " + firstOperand + secondOperand + usedOperator + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString());
 }
 public Condition()
 {
     UCID = HashingEx.Hashing.GetSha1Hash(DateTime.Now.ToString() + " " + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString());
 }
Beispiel #3
0
 public void GenerateNewUtid(string additional)
 {
     UTID = HashingEx.Hashing.GetSha512Hash(DateTime.Now.ToString() + " " + counter++ + additional + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString());
 }
Beispiel #4
0
        public void TimerTemplateRunOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            _timer.Stop();
            Open cmd = new Open(HashingEx.Hashing.GetSha1Hash(DateTime.Now.ToString() + " " + counter++ + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString()));

            _cefControl.AddCefBrowserCommand(cmd);
            UID = cmd.UID;
            Thread.Sleep(1000);
            bool success = true;

            while (true)
            {
                Thread.Sleep(100);
                if (CefControl.BrowserCommandsCompleted.ContainsKey(cmd.UCID))
                {
                    break;
                }
            }

            if (TemplateElements.Count > 0)
            {
                foreach (var templateElement in TemplateElements)
                {
                    if (!RunTemplate(templateElement, _cefControl))
                    {
                        success = false;
                        break;
                    }
                }
            }

            if (AutomaticallyCloseWindowWhenOutOfCommands && CefControl.CefBrowserSessions.ContainsKey(UID) ||
                !success && CefControl.CefBrowserSessions.ContainsKey(UID))
            {
                Quit quit = new Quit(UID);
                _cefControl.AddCefBrowserCommand(quit);
                while (true)
                {
                    Thread.Sleep(100);
                    if (CefControl.BrowserCommandsCompleted.ContainsKey(cmd.UCID))
                    {
                        break;
                    }
                }
            }
            Completed  = true;
            Successful = success;
            bool run = true;

            while (run)
            {
                try
                {
                    TemplateManagement.LockTemplates.AcquireWriterLock(Options.LockTimeOut);
                    if (TemplateManagement.TemplatesInTransit.ContainsKey(UTID))
                    {
                        TemplateManagement.TemplatesCompleted.Add(UTID,
                                                                  TemplateManagement.TemplatesInTransit[UTID]);
                        Template        template = TemplateManagement.TemplatesInTransit[UTID];
                        ProtectedString oldPassword = null, newPassword = null;
                        foreach (var templateAvailableResourceKeyValuePair in template.AvailableResources)
                        {
                            if (
                                BaseObject.ExtractSinglePlaceholderToString(templateAvailableResourceKeyValuePair.Key) ==
                                "" && (templateAvailableResourceKeyValuePair.Value).GetType().Name == "Text")
                            {
                                newPassword = ((Text)templateAvailableResourceKeyValuePair.Value).Value;
                            }
                            if (
                                BaseObject.ExtractSinglePlaceholderToString(templateAvailableResourceKeyValuePair.Key) ==
                                PwDefs.PasswordField &&
                                (templateAvailableResourceKeyValuePair.Value).GetType().Name == "Text")
                            {
                                oldPassword = ((Text)templateAvailableResourceKeyValuePair.Value).Value;
                            }
                        }
                        if (template.SetNewPasswordWhenSuccess)
                        {
                            PwEntry entry =
                                KeePassPasswordChangerExt._mHost.MainWindow.ActiveDatabase.RootGroup.FindEntry(
                                    new PwUuid(template.PwUidBytes),
                                    true);
                            PwEntry newone = new PwEntry(true, true);
                            if (Successful)
                            {
                                newone.Strings.Set(PwDefs.PasswordField,
                                                   new ProtectedString(true, oldPassword.ReadString()));
                                newone.Strings.Set(PwDefs.TitleField, new ProtectedString(true, "Old Password"));
                                entry.History.Add(newone);
                                if (newPassword != null)
                                {
                                    entry.Strings.Set(PwDefs.PasswordField, newPassword);
                                }
                            }
                            else
                            {
                                if (newPassword != null)
                                {
                                    newone.Strings.Set(PwDefs.PasswordField,
                                                       new ProtectedString(true, newPassword.ReadString()));
                                    newone.Strings.Set(PwDefs.TitleField, new ProtectedString(true, "Not applied new password"));
                                    entry.History.Add(newone);
                                }
                            }

                            KeePassPasswordChangerExt._mHost.MainWindow.BeginInvoke((MethodInvoker) delegate()
                            {
                                entry.LastModificationTime = TimeUtil.ToUtc(DateTime.Now, false);
                                KeePassPasswordChangerExt.RefreshUiEntry(entry);
                            });
                            //KeePassPasswordChangerExt.SaveCurrentDb();
                        }
                        TemplateManagement.TemplatesInTransit.Remove(UTID);
                    }
                    run = false;
                }
                catch (ApplicationException ex)
                {
                    ExceptionHandling.Handling.GetException("ReaderWriterLock", ex);
                }
                finally
                {
                    if (TemplateManagement.LockTemplates.IsWriterLockHeld)
                    {
                        TemplateManagement.LockTemplates.ReleaseWriterLock();
                    }
                }
            }

            //_timer.Start();
        }
Beispiel #5
0
 private void GenerateNewUtid()
 {
     UTID = HashingEx.Hashing.GetSha512Hash(DateTime.Now.ToString() + " " + counter++ + KeePassPasswordChangerExt.GeneratePassword(10, true, true, true, true, true, true, false, false).ReadString());
 }