private static CompositeKey KeyFromCommandLine(CommandLineArgs args,
                                                       string strPrefix)
        {
            CompositeKey cmpKey = new CompositeKey();

            string strPw      = args[strPrefix + AppDefs.CommandLineOptions.Password];
            string strPwEnc   = args[strPrefix + AppDefs.CommandLineOptions.PasswordEncrypted];
            string strFile    = args[strPrefix + AppDefs.CommandLineOptions.KeyFile];
            string strUserAcc = args[strPrefix + AppDefs.CommandLineOptions.UserAccount];

            if (strPw != null)
            {
                cmpKey.AddUserKey(new KcpPassword(strPw));
            }
            else if (strPwEnc != null)
            {
                cmpKey.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPwEnc)));
            }

            if (strFile != null)
            {
                cmpKey.AddUserKey(new KcpKeyFile(strFile));
            }

            if (strUserAcc != null)
            {
                cmpKey.AddUserKey(new KcpUserAccount());
            }

            return(cmpKey);
        }
Beispiel #2
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            string           strFile = args.FileName;
            IOConnectionInfo ioc     = (!string.IsNullOrEmpty(strFile) ?
                                        IOConnectionInfo.FromPath(strFile) : new IOConnectionInfo());

            string strPassword      = args[AppDefs.CommandLineOptions.Password];
            string strPasswordEnc   = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string strPasswordStdIn = args[AppDefs.CommandLineOptions.PasswordStdIn];
            string strKeyFile       = args[AppDefs.CommandLineOptions.KeyFile];
            string strUserAcc       = args[AppDefs.CommandLineOptions.UserAccount];

            byte[] pbPasswordUtf8 = null;
            try
            {
                if (strPassword != null)
                {
                    pbPasswordUtf8 = StrUtil.Utf8.GetBytes(strPassword);
                }
                else if (strPasswordEnc != null)
                {
                    pbPasswordUtf8 = StrUtil.Utf8.GetBytes(StrUtil.DecryptString(
                                                               strPasswordEnc));
                }
                else if (strPasswordStdIn != null)
                {
                    ProtectedString ps = ReadPasswordStdIn(true);
                    if (ps == null)
                    {
                        return(null);
                    }
                    pbPasswordUtf8 = ps.ReadUtf8();
                }

                return(CreateKey(pbPasswordUtf8, strKeyFile, (strUserAcc != null),
                                 ioc, false, false));
            }
            catch (Exception ex) { MessageService.ShowWarning(ex); }
            finally
            {
                if (pbPasswordUtf8 != null)
                {
                    MemUtil.ZeroByteArray(pbPasswordUtf8);
                }
                ClearKeyOptions(args, true);
            }

            return(null);
        }
Beispiel #3
0
        private static bool ChangeMasterKey(PwDatabase pwDatabase, CommandLineArgs args)
        {
            const string strNew = "new";

            CompositeKey ck = new CompositeKey();

            string strPw    = args[strNew + AppDefs.CommandLineOptions.Password];
            string strPwEnc = args[strNew + AppDefs.CommandLineOptions.PasswordEncrypted];

            if (strPw != null)
            {
                ck.AddUserKey(new KcpPassword(strPw));
            }
            else if (strPwEnc != null)
            {
                ck.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPwEnc)));
            }

            string strFile = args[strNew + AppDefs.CommandLineOptions.KeyFile];

            if (!string.IsNullOrEmpty(strFile))
            {
                ck.AddUserKey(new KcpKeyFile(strFile));
            }

            string strAcc = args[strNew + AppDefs.CommandLineOptions.UserAccount];

            if (strAcc != null)
            {
                ck.AddUserKey(new KcpUserAccount());
            }

            if (ck.UserKeyCount > 0)
            {
                pwDatabase.MasterKey                = ck;
                pwDatabase.MasterKeyChanged         = DateTime.UtcNow;
                pwDatabase.MasterKeyChangeForceOnce = false;
                return(true);
            }

            return(false);
        }
        private void OnFormLoad(object sender, EventArgs e)
        {
            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);
            // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this);

            string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                                     m_strCustomTitle : KPRes.EnterCompositeKey);
            string strBannerDesc = WinUtil.CompactPath(m_ioInfo.Path, 45);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc);
            this.Icon = AppIcons.Default;

            FontUtil.SetDefaultFont(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbKeyFile);
            FontUtil.AssignDefaultBold(m_cbUserAccount);

            UIUtil.ConfigureToolTip(m_ttRect);
            // m_ttRect.SetToolTip(m_cbHidePassword, KPRes.TogglePasswordAsterisks);
            m_ttRect.SetToolTip(m_btnOpenKeyFile, KPRes.KeyFileSelect);

            PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect);

            string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                               m_strCustomTitle : KPRes.OpenDatabase);
            string strNameEx = UrlUtil.GetFileName(m_ioInfo.Path);

            if (!string.IsNullOrEmpty(strNameEx))
            {
                this.Text = strStart + " - " + strNameEx;
            }
            else
            {
                this.Text = strStart;
            }

            // Must be set manually due to possible object override
            m_tbPassword.TextChanged += this.ProcessTextChangedPassword;

            // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages;
            AddKeyFileSuggPriv(KPRes.NoKeyFileSpecifiedMeta, true);

            // Do not directly compare with Program.CommandLineArgs.FileName,
            // because this may be a relative path instead of an absolute one
            string strCmdLineFile = Program.CommandLineArgs.FileName;

            if ((strCmdLineFile != null) && (Program.MainForm != null))
            {
                strCmdLineFile = Program.MainForm.IocFromCommandLine().Path;
            }
            if ((strCmdLineFile != null) && strCmdLineFile.Equals(m_ioInfo.Path,
                                                                  StrUtil.CaseIgnoreCmp))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn];
                if (str != null)
                {
                    ProtectedString ps = KeyUtil.ReadPasswordStdIn(true);
                    if (ps != null)
                    {
                        m_cbPassword.Checked = true;
                        m_tbPassword.TextEx  = ps;
                    }
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;
                    AddKeyFileSuggPriv(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;
                    AddKeyFileSuggPriv(str, true);
                }
            }

            m_cbHidePassword.Checked = true;
            OnCheckedHidePassword(sender, e);

            Debug.Assert(m_cmbKeyFile.Text.Length != 0);

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            ulong uKpf = Program.Config.UI.KeyPromptFlags;

            UIUtil.ApplyKeyUIFlags(uKpf, m_cbPassword, m_cbKeyFile,
                                   m_cbUserAccount, m_cbHidePassword);

            if ((uKpf & (ulong)AceKeyUIFlags.DisableKeyFile) != 0)
            {
                UIUtil.SetEnabled(m_cmbKeyFile, m_cbKeyFile.Checked);
                UIUtil.SetEnabled(m_btnOpenKeyFile, m_cbKeyFile.Checked);
            }

            if (((uKpf & (ulong)AceKeyUIFlags.CheckPassword) != 0) ||
                ((uKpf & (ulong)AceKeyUIFlags.UncheckPassword) != 0))
            {
                m_bPwStatePreset = true;
            }
            if (((uKpf & (ulong)AceKeyUIFlags.CheckUserAccount) != 0) ||
                ((uKpf & (ulong)AceKeyUIFlags.UncheckUserAccount) != 0))
            {
                m_bUaStatePreset = true;
            }

            CustomizeForScreenReader();
            EnableUserControls();

            m_bInitializing = false;

            // E.g. command line options have higher priority
            m_bCanModKeyFile = (m_cmbKeyFile.SelectedIndex == 0);

            m_aKeyAssoc = Program.Config.Defaults.GetKeySources(m_ioInfo);
            if (m_aKeyAssoc != null)
            {
                if (m_aKeyAssoc.Password && !m_bPwStatePreset)
                {
                    m_cbPassword.Checked = true;
                }

                if (m_aKeyAssoc.KeyFilePath.Length > 0)
                {
                    AddKeyFileSuggPriv(m_aKeyAssoc.KeyFilePath, null);
                }

                if (m_aKeyAssoc.UserAccount && !m_bUaStatePreset)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            foreach (KeyProvider prov in Program.KeyProviderPool)
            {
                AddKeyFileSuggPriv(prov.Name, null);
            }

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.AsyncFormLoad));

            th.Start();
            // ThreadPool.QueueUserWorkItem(new WaitCallback(this.AsyncFormLoad));

            this.BringToFront();
            this.Activate();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }
Beispiel #5
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            GlobalWindowManager.AddWindow(this);
            if (m_bRedirectActivation)
            {
                Program.MainForm.RedirectActivationPush(this);
            }

            m_bInitializing = true;

            string strBannerDesc = WinUtil.CompactPath(m_ioInfo.Path, 45);

            m_bannerImage.Image = BannerFactory.CreateBanner(m_bannerImage.Width,
                                                             m_bannerImage.Height, BannerStyle.Default,
                                                             Properties.Resources.B48x48_KGPG_Key2, KPRes.EnterCompositeKey,
                                                             strBannerDesc);
            this.Icon = Properties.Resources.KeePass;

            FontUtil.AssignDefaultBold(m_cbPassword);
            FontUtil.AssignDefaultBold(m_cbKeyFile);
            FontUtil.AssignDefaultBold(m_cbUserAccount);

            m_ttRect.SetToolTip(m_cbHidePassword, KPRes.TogglePasswordAsterisks);
            m_ttRect.SetToolTip(m_btnOpenKeyFile, KPRes.KeyFileSelect);

            string strNameEx = UrlUtil.GetFileName(m_ioInfo.Path);

            if (strNameEx.Length > 0)
            {
                this.Text += " - " + strNameEx;
            }

            m_tbPassword.Text = string.Empty;
            m_secPassword.Attach(m_tbPassword, ProcessTextChangedPassword, true);

            m_cmbKeyFile.Items.Add(KPRes.NoKeyFileSpecifiedMeta);
            m_cmbKeyFile.SelectedIndex = 0;

            if ((Program.CommandLineArgs.FileName != null) &&
                (m_ioInfo.Path == Program.CommandLineArgs.FileName))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;

                    m_cmbKeyFile.Items.Add(str);
                    m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (str != null)
                {
                    m_cbKeyFile.Checked = true;

                    m_cmbKeyFile.Items.Add(str);
                    m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1;
                }
            }

            m_cbHidePassword.Checked = true;
            OnCheckedHidePassword(sender, e);

            Debug.Assert(m_cmbKeyFile.Text.Length != 0);

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            UIUtil.ApplyKeyUIFlags(Program.Config.UI.KeyPromptFlags,
                                   m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword);

            if ((Program.Config.UI.KeyPromptFlags & (ulong)AceKeyUIFlags.DisableKeyFile) != 0)
            {
                UIUtil.SetEnabled(m_cmbKeyFile, m_cbKeyFile.Checked);
                UIUtil.SetEnabled(m_btnOpenKeyFile, m_cbKeyFile.Checked);
            }

            CustomizeForScreenReader();
            EnableUserControls();

            m_bInitializing = false;

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.AsyncFormLoad));

            th.Start();

            this.BringToFront();
            this.Activate();
            m_tbPassword.Focus();
        }
Beispiel #6
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            CompositeKey cmpKey         = new CompositeKey();
            string       strPassword    = args[AppDefs.CommandLineOptions.Password];
            string       strPasswordEnc = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string       strKeyFile     = args[AppDefs.CommandLineOptions.KeyFile];
            string       strUserAcc     = args[AppDefs.CommandLineOptions.UserAccount];

            if (strPassword != null)
            {
                cmpKey.AddUserKey(new KcpPassword(strPassword));
            }
            else if (strPasswordEnc != null)
            {
                cmpKey.AddUserKey(new KcpPassword(StrUtil.DecryptString(strPasswordEnc)));
            }

            if (strKeyFile != null)
            {
                if (Program.KeyProviderPool.IsKeyProvider(strKeyFile))
                {
                    KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                        IOConnectionInfo.FromPath(args.FileName), false, false);

                    bool   bPerformHash;
                    byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                                                                      out bPerformHash);
                    if ((pbProvKey != null) && (pbProvKey.Length > 0))
                    {
                        try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
                        catch (Exception exCKP)
                        {
                            MessageService.ShowWarning(exCKP);
                            return(null);
                        }

                        Array.Clear(pbProvKey, 0, pbProvKey.Length);
                    }
                    else
                    {
                        return(null);                     // Provider has shown error message
                    }
                }
                else                 // Key file
                {
                    try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                    catch (Exception exKey)
                    {
                        MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                        return(null);
                    }
                }
            }

            if (strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch (Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return(null);
                }
            }

            if (cmpKey.UserKeyCount > 0)
            {
                ClearKeyOptions(args, true);
                return(cmpKey);
            }

            return(null);
        }
Beispiel #7
0
        public static CompositeKey KeyFromCommandLine(CommandLineArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            CompositeKey cmpKey           = new CompositeKey();
            string       strPassword      = args[AppDefs.CommandLineOptions.Password];
            string       strPasswordEnc   = args[AppDefs.CommandLineOptions.PasswordEncrypted];
            string       strPasswordStdIn = args[AppDefs.CommandLineOptions.PasswordStdIn];
            string       strKeyFile       = args[AppDefs.CommandLineOptions.KeyFile];
            string       strUserAcc       = args[AppDefs.CommandLineOptions.UserAccount];

            Action <byte[]> fAddPwB = delegate(byte[] pbPw)
            {
                cmpKey.AddUserKey(new KcpPassword(pbPw,
                                                  Program.Config.Security.MasterPassword.RememberWhileOpen));
            };

            Action <string> fAddPwS = delegate(string strPw)
            {
                byte[] pb = StrUtil.Utf8.GetBytes(strPw);
                try { fAddPwB(pb); }
                finally { MemUtil.ZeroByteArray(pb); }
            };

            if (strPassword != null)
            {
                fAddPwS(strPassword);
            }
            else if (strPasswordEnc != null)
            {
                fAddPwS(StrUtil.DecryptString(strPasswordEnc));
            }
            else if (strPasswordStdIn != null)
            {
                ProtectedString ps = ReadPasswordStdIn(true);
                if (ps != null)
                {
                    byte[] pb = ps.ReadUtf8();
                    try { fAddPwB(pb); }
                    finally { MemUtil.ZeroByteArray(pb); }
                }
            }

            if (strKeyFile != null)
            {
                if (Program.KeyProviderPool.IsKeyProvider(strKeyFile))
                {
                    KeyProviderQueryContext ctxKP = new KeyProviderQueryContext(
                        IOConnectionInfo.FromPath(args.FileName), false, false);

                    bool   bPerformHash;
                    byte[] pbProvKey = Program.KeyProviderPool.GetKey(strKeyFile, ctxKP,
                                                                      out bPerformHash);
                    if ((pbProvKey != null) && (pbProvKey.Length > 0))
                    {
                        try { cmpKey.AddUserKey(new KcpCustomKey(strKeyFile, pbProvKey, bPerformHash)); }
                        catch (Exception exCKP)
                        {
                            MessageService.ShowWarning(exCKP);
                            return(null);
                        }
                        finally { MemUtil.ZeroByteArray(pbProvKey); }
                    }
                    else
                    {
                        return(null);                     // Provider has shown error message
                    }
                }
                else                 // Key file
                {
                    try { cmpKey.AddUserKey(new KcpKeyFile(strKeyFile)); }
                    catch (Exception exKey)
                    {
                        MessageService.ShowWarning(strKeyFile, KPRes.KeyFileError, exKey);
                        return(null);
                    }
                }
            }

            if (strUserAcc != null)
            {
                try { cmpKey.AddUserKey(new KcpUserAccount()); }
                catch (Exception exUA)
                {
                    MessageService.ShowWarning(exUA);
                    return(null);
                }
            }

            if (cmpKey.UserKeyCount > 0)
            {
                ClearKeyOptions(args, true);
                return(cmpKey);
            }

            return(null);
        }
Beispiel #8
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            ++m_uUIAutoBlocked;

            // The password text box should not be focused by default
            // in order to avoid a Caps Lock warning tooltip bug;
            // https://sourceforge.net/p/keepass/bugs/1807/
            Debug.Assert((m_tbPassword.TabIndex >= 2) && !m_tbPassword.Focused);

            GlobalWindowManager.AddWindow(this);
            // if(m_bRedirectActivation) Program.MainForm.RedirectActivationPush(this);

            string strBannerTitle = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                                     m_strCustomTitle : KPRes.EnterCompositeKey);
            string strBannerDesc = m_ioInfo.GetDisplayName();             // Compacted by banner

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_KGPG_Key2, strBannerTitle, strBannerDesc);
            this.Icon = AppIcons.Default;

            string strStart = (!string.IsNullOrEmpty(m_strCustomTitle) ?
                               m_strCustomTitle : KPRes.OpenDatabase);
            string strName = UrlUtil.GetFileName(m_ioInfo.Path);

            if (!string.IsNullOrEmpty(strName))
            {
                this.Text = strStart + " - " + strName;
            }
            else
            {
                this.Text = strStart;
            }

            FontUtil.SetDefaultFont(m_cbPassword);
            // FontUtil.AssignDefaultBold(m_cbPassword);
            // FontUtil.AssignDefaultBold(m_cbKeyFile);
            // FontUtil.AssignDefaultBold(m_cbUserAccount);

            UIUtil.ConfigureToolTip(m_ttRect);
            UIUtil.SetToolTip(m_ttRect, m_btnOpenKeyFile, KPRes.KeyFileSelect, true);

            UIUtil.AccSetName(m_tbPassword, m_cbPassword);
            UIUtil.AccSetName(m_cmbKeyFile, m_cbKeyFile);

            PwInputControlGroup.ConfigureHideButton(m_cbHidePassword, m_ttRect);

            // Enable protection before possibly setting a text
            m_cbHidePassword.Checked = true;
            OnHidePasswordCheckedChanged(null, EventArgs.Empty);

            // Must be set manually due to possible object override
            m_tbPassword.TextChanged += this.OnPasswordTextChanged;

            // m_cmbKeyFile.OrderedImageList = m_lKeyFileImages;
            AddKeyFileItem(KPRes.NoKeyFileSpecifiedMeta, true);

            Debug.Assert(!AnyComponentOn());

            // Do not directly compare with Program.CommandLineArgs.FileName,
            // because this may be a relative path instead of an absolute one
            string strCmdLineFile = Program.CommandLineArgs.FileName;

            if (!string.IsNullOrEmpty(strCmdLineFile) && (Program.MainForm != null))
            {
                strCmdLineFile = Program.MainForm.IocFromCommandLine().Path;
            }
            if (!string.IsNullOrEmpty(strCmdLineFile) && strCmdLineFile.Equals(
                    m_ioInfo.Path, StrUtil.CaseIgnoreCmp))
            {
                string str;

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.Password];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = str;
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordEncrypted];
                if (str != null)
                {
                    m_cbPassword.Checked = true;
                    m_tbPassword.Text    = StrUtil.DecryptString(str);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PasswordStdIn];
                if (str != null)
                {
                    ProtectedString ps = KeyUtil.ReadPasswordStdIn(true);
                    if (ps != null)
                    {
                        m_cbPassword.Checked = true;
                        m_tbPassword.TextEx  = ps;
                    }
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.KeyFile];
                if (!string.IsNullOrEmpty(str))
                {
                    AddKeyFileItem(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.PreSelect];
                if (!string.IsNullOrEmpty(str))
                {
                    AddKeyFileItem(str, true);
                }

                str = Program.CommandLineArgs[AppDefs.CommandLineOptions.UserAccount];
                if (str != null)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            AceKeyAssoc a = Program.Config.Defaults.GetKeySources(m_ioInfo);

            if ((a != null) && !AnyComponentOn())
            {
                if (a.Password)
                {
                    m_cbPassword.Checked = true;
                }

                if (!string.IsNullOrEmpty(a.KeyFilePath))
                {
                    AddKeyFileItem(a.KeyFilePath, true);
                }
                if (!string.IsNullOrEmpty(a.KeyProvider))
                {
                    AddKeyFileItem(a.KeyProvider, true);
                }

                if (a.UserAccount)
                {
                    m_cbUserAccount.Checked = true;
                }
            }

            foreach (KeyProvider kp in Program.KeyProviderPool)
            {
                AddKeyFileItem(kp.Name, false);
            }

            UIUtil.ApplyKeyUIFlags(Program.Config.UI.KeyPromptFlags,
                                   m_cbPassword, m_cbKeyFile, m_cbUserAccount, m_cbHidePassword);

            if (!m_cbPassword.Enabled && !m_cbPassword.Checked)
            {
                m_tbPassword.Text = string.Empty;
                UIUtil.SetEnabledFast(false, m_tbPassword, m_cbHidePassword);
            }

            if (!m_cbKeyFile.Enabled && !m_cbKeyFile.Checked)
            {
                UIUtil.SetEnabledFast(false, m_cmbKeyFile, m_btnOpenKeyFile);
            }

            if (WinUtil.IsWindows9x || NativeLib.IsUnix())
            {
                UIUtil.SetChecked(m_cbUserAccount, false);
                UIUtil.SetEnabled(m_cbUserAccount, false);
            }

            m_btnExit.Enabled = m_bCanExit;
            m_btnExit.Visible = m_bCanExit;

            --m_uUIAutoBlocked;
            UpdateUIState();

            // Local, but thread will continue to run anyway
            Thread th = new Thread(new ThreadStart(this.OnFormLoadAsync));

            th.Start();
            // ThreadPool.QueueUserWorkItem(new WaitCallback(this.OnFormLoadAsync));

            this.BringToFront();
            this.Activate();
            // UIUtil.SetFocus(m_tbPassword, this); // See OnFormShown
        }