Commits

Devin Martin committed fe6461f

Add banner to configuration screen. Add a custom options checkbox to improve configuration. Hide the incomplete checkboxes for encodings.

  • Participants
  • Parent commits f55d809

Comments (0)

Files changed (4)

File KeeOtp/OtpInformation.Designer.cs

             this.radioButtonBase32 = new System.Windows.Forms.RadioButton();
             this.radioButtonBase64 = new System.Windows.Forms.RadioButton();
             this.radioButtonHex = new System.Windows.Forms.RadioButton();
+            this.pictureBoxBanner = new System.Windows.Forms.PictureBox();
+            this.checkBoxCustomSettings = new System.Windows.Forms.CheckBox();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBanner)).BeginInit();
             this.SuspendLayout();
             // 
             // textBoxKey
             // 
-            this.textBoxKey.Location = new System.Drawing.Point(31, 31);
+            this.textBoxKey.Location = new System.Drawing.Point(31, 85);
             this.textBoxKey.Name = "textBoxKey";
-            this.textBoxKey.Size = new System.Drawing.Size(231, 20);
+            this.textBoxKey.Size = new System.Drawing.Size(340, 20);
             this.textBoxKey.TabIndex = 0;
             this.textBoxKey.TextChanged += new System.EventHandler(this.textBoxKey_TextChanged);
             // 
             // textBoxStep
             // 
-            this.textBoxStep.Location = new System.Drawing.Point(140, 138);
+            this.textBoxStep.Location = new System.Drawing.Point(140, 224);
             this.textBoxStep.Name = "textBoxStep";
             this.textBoxStep.Size = new System.Drawing.Size(23, 20);
             this.textBoxStep.TabIndex = 1;
             // radioButtonSix
             // 
             this.radioButtonSix.AutoSize = true;
-            this.radioButtonSix.Checked = true;
-            this.radioButtonSix.Location = new System.Drawing.Point(140, 174);
+            this.radioButtonSix.Location = new System.Drawing.Point(140, 260);
             this.radioButtonSix.Name = "radioButtonSix";
             this.radioButtonSix.Size = new System.Drawing.Size(60, 17);
             this.radioButtonSix.TabIndex = 2;
-            this.radioButtonSix.TabStop = true;
             this.radioButtonSix.Text = "6 Digits";
             this.radioButtonSix.UseVisualStyleBackColor = true;
             // 
             // labelKey
             // 
             this.labelKey.AutoSize = true;
-            this.labelKey.Location = new System.Drawing.Point(28, 15);
+            this.labelKey.Location = new System.Drawing.Point(28, 69);
             this.labelKey.Name = "labelKey";
             this.labelKey.Size = new System.Drawing.Size(25, 13);
             this.labelKey.TabIndex = 3;
             // label2
             // 
             this.label2.AutoSize = true;
-            this.label2.Location = new System.Drawing.Point(28, 141);
+            this.label2.Location = new System.Drawing.Point(28, 227);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(106, 13);
             this.label2.TabIndex = 4;
             // labelSize
             // 
             this.labelSize.AutoSize = true;
-            this.labelSize.Location = new System.Drawing.Point(79, 174);
+            this.labelSize.Location = new System.Drawing.Point(79, 260);
             this.labelSize.Name = "labelSize";
             this.labelSize.Size = new System.Drawing.Size(55, 13);
             this.labelSize.TabIndex = 5;
             // radioButtonEight
             // 
             this.radioButtonEight.AutoSize = true;
-            this.radioButtonEight.Location = new System.Drawing.Point(140, 197);
+            this.radioButtonEight.Location = new System.Drawing.Point(140, 283);
             this.radioButtonEight.Name = "radioButtonEight";
             this.radioButtonEight.Size = new System.Drawing.Size(60, 17);
             this.radioButtonEight.TabIndex = 6;
             // 
             this.buttonOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonOk.DialogResult = System.Windows.Forms.DialogResult.OK;
-            this.buttonOk.Location = new System.Drawing.Point(106, 236);
+            this.buttonOk.Location = new System.Drawing.Point(215, 310);
             this.buttonOk.Name = "buttonOk";
             this.buttonOk.Size = new System.Drawing.Size(75, 23);
             this.buttonOk.TabIndex = 7;
             // 
             this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-            this.buttonCancel.Location = new System.Drawing.Point(187, 236);
+            this.buttonCancel.Location = new System.Drawing.Point(296, 310);
             this.buttonCancel.Name = "buttonCancel";
             this.buttonCancel.Size = new System.Drawing.Size(75, 23);
             this.buttonCancel.TabIndex = 8;
             // radioButtonBase32
             // 
             this.radioButtonBase32.AutoSize = true;
-            this.radioButtonBase32.Location = new System.Drawing.Point(31, 57);
+            this.radioButtonBase32.Checked = true;
+            this.radioButtonBase32.Location = new System.Drawing.Point(31, 143);
             this.radioButtonBase32.Name = "radioButtonBase32";
             this.radioButtonBase32.Size = new System.Drawing.Size(64, 17);
             this.radioButtonBase32.TabIndex = 9;
             this.radioButtonBase32.TabStop = true;
             this.radioButtonBase32.Text = "Base 32";
             this.radioButtonBase32.UseVisualStyleBackColor = true;
+            this.radioButtonBase32.Visible = false;
             // 
             // radioButtonBase64
             // 
             this.radioButtonBase64.AutoSize = true;
-            this.radioButtonBase64.Location = new System.Drawing.Point(31, 80);
+            this.radioButtonBase64.Location = new System.Drawing.Point(31, 166);
             this.radioButtonBase64.Name = "radioButtonBase64";
             this.radioButtonBase64.Size = new System.Drawing.Size(64, 17);
             this.radioButtonBase64.TabIndex = 10;
-            this.radioButtonBase64.TabStop = true;
             this.radioButtonBase64.Text = "Base 64";
             this.radioButtonBase64.UseVisualStyleBackColor = true;
+            this.radioButtonBase64.Visible = false;
             // 
             // radioButtonHex
             // 
             this.radioButtonHex.AutoSize = true;
-            this.radioButtonHex.Location = new System.Drawing.Point(31, 103);
+            this.radioButtonHex.Location = new System.Drawing.Point(31, 189);
             this.radioButtonHex.Name = "radioButtonHex";
             this.radioButtonHex.Size = new System.Drawing.Size(44, 17);
             this.radioButtonHex.TabIndex = 11;
-            this.radioButtonHex.TabStop = true;
             this.radioButtonHex.Text = "Hex";
             this.radioButtonHex.UseVisualStyleBackColor = true;
+            this.radioButtonHex.Visible = false;
+            // 
+            // pictureBoxBanner
+            // 
+            this.pictureBoxBanner.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.pictureBoxBanner.Location = new System.Drawing.Point(0, -1);
+            this.pictureBoxBanner.Name = "pictureBoxBanner";
+            this.pictureBoxBanner.Size = new System.Drawing.Size(383, 58);
+            this.pictureBoxBanner.TabIndex = 12;
+            this.pictureBoxBanner.TabStop = false;
+            // 
+            // checkBoxCustomSettings
+            // 
+            this.checkBoxCustomSettings.AutoSize = true;
+            this.checkBoxCustomSettings.Location = new System.Drawing.Point(31, 112);
+            this.checkBoxCustomSettings.Name = "checkBoxCustomSettings";
+            this.checkBoxCustomSettings.Size = new System.Drawing.Size(124, 17);
+            this.checkBoxCustomSettings.TabIndex = 13;
+            this.checkBoxCustomSettings.Text = "Use Custom Settings";
+            this.checkBoxCustomSettings.UseVisualStyleBackColor = true;
+            this.checkBoxCustomSettings.CheckedChanged += new System.EventHandler(this.checkBoxCustomSettings_CheckedChanged);
             // 
             // OtpInformation
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(274, 271);
+            this.ClientSize = new System.Drawing.Size(383, 345);
+            this.Controls.Add(this.checkBoxCustomSettings);
+            this.Controls.Add(this.pictureBoxBanner);
             this.Controls.Add(this.radioButtonHex);
             this.Controls.Add(this.radioButtonBase64);
             this.Controls.Add(this.radioButtonBase32);
             this.Controls.Add(this.radioButtonSix);
             this.Controls.Add(this.textBoxStep);
             this.Controls.Add(this.textBoxKey);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
             this.Name = "OtpInformation";
-            this.Text = "OtpInformation";
+            this.Text = "Configuration";
             this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OtpInformation_FormClosing);
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBanner)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
         private System.Windows.Forms.RadioButton radioButtonBase32;
         private System.Windows.Forms.RadioButton radioButtonBase64;
         private System.Windows.Forms.RadioButton radioButtonHex;
+        private System.Windows.Forms.PictureBox pictureBoxBanner;
+        private System.Windows.Forms.CheckBox checkBoxCustomSettings;
     }
 }

File KeeOtp/OtpInformation.cs

     {
         const string validKeyChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
         public OtpAuthData Data { get; set; }
+        bool fullyLoaded = false;
 
         public OtpInformation(IPluginHost host)
         {
             InitializeComponent();
             this.Shown += (sender, e) => FormWasShown();
+
+            pictureBoxBanner.Image = KeePass.UI.BannerFactory.CreateBanner(pictureBoxBanner.Width,
+                pictureBoxBanner.Height,
+                KeePass.UI.BannerStyle.Default,
+                Resources.lock_key.GetThumbnailImage(32, 32, null, IntPtr.Zero),
+                "Configuration",
+                "Set up the key for generating one time passwords");
+
             this.Icon = host.MainWindow.Icon;
         }
 
                     this.radioButtonSix.Checked = true;
                     this.radioButtonEight.Checked = false;
                 }
+
+                if (this.Data.Size != 6 || this.Data.Step != 30)
+                {
+                    this.checkBoxCustomSettings.Checked = true;
+                }
             }
             else
                 this.textBoxStep.Text = "30";
+
+            SetCustomSettingsState(false);
+            this.fullyLoaded = true;
         }
 
         private void OtpInformation_FormClosing(object sender, FormClosingEventArgs e)
                     return;
                 }
 
-                var size = (this.radioButtonEight.Checked) ? 8 : 6;
-                int step;
+                // set the default settings
+                int size = 6;
+                int step = 30;
+                Key key = null;
 
-                if (int.TryParse(this.textBoxStep.Text, out step))
+                if (this.checkBoxCustomSettings.Checked)
                 {
-                    if (step != 30)
+                    size = (this.radioButtonEight.Checked) ? 8 : 6;
+                    if (int.TryParse(this.textBoxStep.Text, out step))
                     {
-                        if (step <= 0)
+                        if (step != 30)
                         {
-                            this.textBoxStep.Text = "30";
-                            MessageBox.Show("The time step must be a non-zero positive integer.  The standard value is 30.  If you weren't specifically given an alternate value just use 30.");
-                            e.Cancel = true;
-                            return;
-                        }
-                        else if (MessageBox.Show("You have selected a non-standard time step.  30 is the standard recommended value.  You should only proceed if you were specifically told to use this time step size.  Do you wish to proceed?", "Non-standard time step size", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
-                        {
-                            e.Cancel = true;
-                            return;
+                            if (step <= 0)
+                            {
+                                this.textBoxStep.Text = "30";
+                                MessageBox.Show("The time step must be a non-zero positive integer.  The standard value is 30.  If you weren't specifically given an alternate value just use 30.");
+                                e.Cancel = true;
+                                return;
+                            }
+                            else if (MessageBox.Show("You have selected a non-standard time step.  30 is the standard recommended value.  You should only proceed if you were specifically told to use this time step size.  Do you wish to proceed?", "Non-standard time step size", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
+                            {
+                                e.Cancel = true;
+                                return;
+                            }
                         }
                     }
+                    else
+                    {
+                        this.textBoxStep.Text = "30";
+                        MessageBox.Show("The time step must be a non-zero positive integer.  The standard value is 30.  If you weren't specifically given an alternate value just use 30.");
+                        e.Cancel = true;
+                        return;
+                    }
+                    // need to do encoding here
+                    key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(this.textBoxKey.Text.Replace(" ", string.Empty)));
                 }
                 else
-                {
-                    this.textBoxStep.Text = "30";
-                    MessageBox.Show("The time step must be a non-zero positive integer.  The standard value is 30.  If you weren't specifically given an alternate value just use 30.");
-                    e.Cancel = true;
-                    return;
-                }
+                    key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(this.textBoxKey.Text.Replace(" ", string.Empty)));
 
-                var key = ProtectedKey.CreateProtectedKeyAndDestroyPlaintextKey(Base32.Decode(this.textBoxKey.Text.Replace(" ", string.Empty)));
                 this.Data = new OtpAuthData()
                 {
                     Key = key,
 
         private void textBoxKey_TextChanged(object sender, EventArgs e)
         {
-            var unpaddedBase32 = this.textBoxKey.Text.Replace(" ", string.Empty).ToUpperInvariant().TrimEnd('=');
+            var unpaddedBase32 = this.textBoxKey.Text.Replace(" ", string.Empty).Replace("-", string.Empty).ToUpperInvariant().TrimEnd('=');
 
             bool invalid = false;
             foreach (var c in unpaddedBase32)
                     this.textBoxKey.Text = string.Empty;
             }
         }
+
+        private void checkBoxCustomSettings_CheckedChanged(object sender, EventArgs e)
+        {
+            SetCustomSettingsState(this.fullyLoaded);
+        }
+
+        private void SetCustomSettingsState(bool showWarning)
+        {
+            var useCustom = this.checkBoxCustomSettings.Checked;
+
+            if (useCustom && showWarning)
+                MessageBox.Show("Most providers use the default settings. Be sure that the provider requires these custom settings.", "Custom Settings");
+
+            this.radioButtonBase32.Enabled =
+                this.radioButtonBase64.Enabled =
+                this.radioButtonHex.Enabled =
+                this.radioButtonSix.Enabled =
+                this.radioButtonEight.Enabled =
+                this.textBoxStep.Enabled = useCustom;
+        }
     }
 }

File KeeOtp/OtpInformation.resx

     <value>2.0</value>
   </resheader>
   <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   <resheader name="writer">
-    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
 </root>

File KeeOtp/Properties/AssemblyInfo.cs

 [assembly: Guid("9CCC719B-32BA-4936-A6D7-DBF0659C16EF")]
 
 // Assembly version information
-[assembly: AssemblyVersion("1.1.0")]
-[assembly: AssemblyFileVersion("1.1.0")]
+[assembly: AssemblyVersion("1.2.0")]
+[assembly: AssemblyFileVersion("1.2.0")]