Skip to content

Commit

Permalink
Add security to Port text field to prevent other characters
Browse files Browse the repository at this point in the history
  • Loading branch information
GreepTheSheep committed Jun 30, 2022
1 parent a984516 commit 4ae3334
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions UI/Components/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion UI/Components/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ public string GetIP()
public string PortString
{
get { return Port.ToString(); }
set { Port = ushort.Parse(value); }
set
{
try
{
Port = ushort.Parse(value);
}
catch (Exception)
{
Port = 16934;
}
}
}

public Settings(ServerComponent component)
Expand Down Expand Up @@ -98,5 +108,14 @@ private void buttonStatus_Click(object sender, EventArgs e)
ServerComponent.Start();
}
}

private void txtPort_KeyPress(object sender, KeyPressEventArgs e)
{
// Verify that the pressed key isn't CTRL or any non-numeric digit
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.'))
{
e.Handled = true;
}
}
}
}

0 comments on commit 4ae3334

Please sign in to comment.