input validation

This commit is contained in:
clowwindy
2014-11-07 01:44:31 +08:00
parent 1de2d001d7
commit 0859d03f4d
2 changed files with 30 additions and 2 deletions
+28
View File
@@ -58,8 +58,36 @@ namespace shadowsocks_csharp
}
}
private static void checkPort(int port)
{
if (port <= 0 || port > 65535)
{
throw new ArgumentException("port out of range");
}
}
private static void checkPassword(string password)
{
if (string.IsNullOrEmpty(password))
{
throw new ArgumentException("password can not be blank");
}
}
private static void checkServer(string server)
{
if (string.IsNullOrEmpty(server))
{
throw new ArgumentException("server can not be blank");
}
}
public static void Save(Config config)
{
checkPort(config.local_port);
checkPort(config.server_port);
checkPassword(config.password);
checkServer(config.server);
try
{
using (StreamWriter sw = new StreamWriter(File.Open(@"config.json", FileMode.Create)))
+2 -2
View File
@@ -93,11 +93,11 @@ namespace shadowsocks_csharp
}
catch (FormatException)
{
MessageBox.Show("there is format problem");
MessageBox.Show("illegal port number format");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show(ex.Message);
}
}