Exemple #1
0
        private void Timer1Tick(object sender, EventArgs e)
        {
            long   lCounter = this._counter[0];
            long   lSecToGo = this._counter[1];
            string sCopyTxt = "";
            Color  cMyColor = Color.Black;

            if (lSecToGo == 0)
            {
                try {
                    Clipboard.Clear();
                }
                catch {
                    // Just ignore on any error
                }

                for (int i = 0; i < this._TOTPAccounts.Count; i++)
                {
                    this._TOTPAccounts[i].CurrentCode =
                        TOTP_GA.GeneratePassword(this._TOTPAccounts[i].Key, lCounter, this._TOTPAccounts[i].CodeLen);
                }
            }
            if (lSecToGo < 4 || lSecToGo > 26)
            {
                cMyColor = Color.Red;
            }
            else
            {
                cMyColor = Color.Black;
            }
            sCopyTxt = "Copy Code (" + (30 - lSecToGo).ToString("00") + " s)";

            for (int i = 0; i < this._TOTPAccounts.Count; i++)
            {
                this._TOTPAccounts[i].MenuItem.DropDown.Items[0].ForeColor = cMyColor;
                this._TOTPAccounts[i].MenuItem.DropDown.Items[1].Text      = sCopyTxt;
            }
        }
Exemple #2
0
        public HiddenMain()
        {
            this.Hide();

            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
            // Prepare the configuration file path
            if (!Directory.Exists(this._sConfPath))
            {
                DirectoryInfo confDirInfo = Directory.CreateDirectory(this._sConfPath);
                confDirInfo.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
            }
            // The config file map
            ExeConfigurationFileMap confFileMap = new ExeConfigurationFileMap();

            confFileMap.ExeConfigFilename = this._sConfPath + "totp.config";

            // Prepare related objects
            this._confApp    = ConfigurationManager.OpenMappedExeConfiguration(confFileMap, ConfigurationUserLevel.None);
            this._TOTPSecret = (TOTP_Secret)this._confApp.GetSection(this._sTOTPSectionName);
            if (null == this._TOTPSecret)
            {
                this._TOTPSecret = new TOTP_Secret();
                this._confApp.Sections.Add(this._sTOTPSectionName, this._TOTPSecret);

                this._TOTPSecret.SectionInformation.ProtectSection(this._sSecretProtect);
                this._TOTPSecret.SectionInformation.ForceSave = true;

                this._confApp.Save(ConfigurationSaveMode.Full, true);
            }
            this._TOTPAccounts = this._TOTPSecret.TOTPAccounts;
            if (this._TOTPAccounts.Count == 0)
            {
                this._intFirstRun = 1;
                this.AddNewAcct(null, null);
            }

            // Load accounts in menu
            for (int i = 0; i < this._TOTPAccounts.Count; i++)
            {
                this._TOTPAccounts[i].MenuItem    = this.CreateAcctMenu(this._TOTPAccounts[i].ID);
                this._TOTPAccounts[i].CurrentCode =
                    TOTP_GA.GeneratePassword(this._TOTPAccounts[i].Key, this._counter[0], this._TOTPAccounts[i].CodeLen);

                this.msTrayIcon.Items.Insert(i + 1,
                                             this._TOTPAccounts[i].MenuItem);
            }

            // Tooltip only on first run
            if (this._intFirstRun == 1)
            {
                this.trayIcon.ShowBalloonTip(5000);
            }

            // Start timer
            this.timer1.Start();
        }