Exemple #1
0
 private void timerUpdateTotp_Tick(object sender, EventArgs e)
 {
     if (textBoxKey.Text.Length > 0)
     {
         try
         {
             OtpAuthData data = readData();
             OtpBase     otp  = OtpAuthUtils.getOtp(data);
             if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
             {
                 groupBoxKey.Text = String.Format(KeeOtp2Statics.OtpInformationKeyUriTotpPreview, otp.getTotpString(OtpTime.getTime()), otp.getRemainingSeconds(OtpTime.getTime()));
             }
             else if (data.Type == OtpType.Hotp)
             {
                 groupBoxKey.Text = String.Format(KeeOtp2Statics.OtpInformationKeyUriHotpPreview, otp.getHotpString(data.Counter));
             }
         }
         catch
         {
             groupBoxKey.Text = KeeOtp2Statics.OtpInformationKeyUriInvalid;
         }
     }
     else
     {
         groupBoxKey.Text = KeeOtp2Statics.OtpInformationKeyUri;
     }
 }
Exemple #2
0
        private void UpdateDisplay()
        {
            if (reloadCount > reloadDataDelay * (1000 / timerUpdateOtp.Interval))
            {
                loadData();
                reloadCount = 0;
            }
            reloadCount++;

            if (this.otp != null)
            {
                if (data.Type == OtpType.Totp || data.Type == OtpType.Steam)
                {
                    this.linkLabelIncorrectNext.Text = KeeOtp2Statics.ShowOtpIncorrect;
                    this.labelOtp.Text     = insertSpaceInMiddle(otp.getTotpString(OtpTime.getTime()));
                    this.groupboxTotp.Text = String.Format(KeeOtp2Statics.ShowOtpNextRemaining, otp.getRemainingSeconds(OtpTime.getTime()).ToString().PadLeft(2, '0'), insertSpaceInMiddle(otp.getTotpString(OtpTime.getTime().AddSeconds(data.Period))));
                }
                else if (data.Type == OtpType.Hotp)
                {
                    this.linkLabelIncorrectNext.Text = KeeOtp2Statics.ShowOtpNextCode;
                    this.labelOtp.Text     = insertSpaceInMiddle(otp.getHotpString(data.Counter));
                    this.groupboxTotp.Text = String.Format(KeeOtp2Statics.ShowOtpNextCounter, data.Counter, insertSpaceInMiddle(otp.getHotpString(data.Counter + 1)));
                }
                if (labelOtp.Width - TextRenderer.MeasureText(labelOtp.Text, new Font(labelOtp.Font.FontFamily, labelOtp.Font.Size, labelOtp.Font.Style)).Width > 30)
                {
                    labelOtp.Font = new Font(labelOtp.Font.FontFamily, 48f, labelOtp.Font.Style);
                }
                else
                {
                    while (labelOtp.Width < TextRenderer.MeasureText(labelOtp.Text, new Font(labelOtp.Font.FontFamily, labelOtp.Font.Size, labelOtp.Font.Style)).Width)
                    {
                        labelOtp.Font = new Font(labelOtp.Font.FontFamily, labelOtp.Font.Size - 0.5f, labelOtp.Font.Style);
                    }
                }
            }
            else
            {
                if (MessageBox.Show(KeeOtp2Statics.MessageBoxOtpNotConfigured, KeeOtp2Statics.ShowOtp, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    AddEdit();
                }
                else
                {
                    this.Close();
                }
            }
        }