Devin Martin avatar Devin Martin committed 6a7dd4a

Add extra validation to the edit dialog. This will warn against non-standard values and prevent error cases. This will fix issue #3

Comments (0)

Files changed (2)

OtpInformation.Designer.cs

             this.textBoxStep.Name = "textBoxStep";
             this.textBoxStep.Size = new System.Drawing.Size(23, 20);
             this.textBoxStep.TabIndex = 1;
-            this.textBoxStep.TextChanged += new System.EventHandler(this.textBoxStep_TextChanged);
             // 
             // radioButtonSix
             // 

OtpInformation.cs

         {
             if (this.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                 return;
-
             try
             {
                 if (string.IsNullOrEmpty(this.textBoxKey.Text))
 
                 if (this.textBoxKey.Text.Length < 8)
                 {
-                    MessageBox.Show("Key must be at least 8 characters.  If you are provided less data then fill it out with '='s");
+                    MessageBox.Show("Key must be at least 8 characters.  If you are provided with less data then pad it up to 8 characters with '='s");
                     e.Cancel = true;
                     return;
                 }
 
                 var size = (this.radioButtonEight.Checked) ? 8 : 6;
-                var step = int.Parse(this.textBoxStep.Text);
+                int step;
+                
+                if (int.TryParse(this.textBoxStep.Text, out step))
+                {
+                    if (step != 30)
+                    {
+                        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;
+                }
+
                 var key = Base32.Decode(this.textBoxKey.Text);
 
                 this.Data = new OtpAuthData()
             }
         }
 
-        private void textBoxStep_TextChanged(object sender, EventArgs e)
-        {
-            var text = this.textBoxStep.Text;
-            int value;
-            if (!int.TryParse(text, out value))
-                this.textBoxStep.Text = "30";
-        }
-
         private void textBoxKey_TextChanged(object sender, EventArgs e)
         {
             var unpaddedBase32 = this.textBoxKey.Text.ToUpperInvariant().TrimEnd('=');
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.