mirror of
https://github.com/awatertrevi/xamarin-neo4j.git
synced 2026-10-08 10:34:04 +00:00
Validate ip address and port
This commit is contained in:
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Acr.UserDialogs;
|
using Acr.UserDialogs;
|
||||||
using Xamarin.Essentials;
|
using Xamarin.Essentials;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
@@ -41,7 +43,7 @@ namespace Xamarin.Neo4j.ViewModels
|
|||||||
|
|
||||||
Commands.Add("Test", new Command(async () =>
|
Commands.Add("Test", new Command(async () =>
|
||||||
{
|
{
|
||||||
// TODO: Validate input.
|
if (!ValidateInput()) return;
|
||||||
|
|
||||||
var connectionString = BuildConnectionString();
|
var connectionString = BuildConnectionString();
|
||||||
|
|
||||||
@@ -52,7 +54,7 @@ namespace Xamarin.Neo4j.ViewModels
|
|||||||
|
|
||||||
Commands.Add("Save", new Command(async () =>
|
Commands.Add("Save", new Command(async () =>
|
||||||
{
|
{
|
||||||
// TODO: Validate input.
|
if (!ValidateInput()) return;
|
||||||
|
|
||||||
var connectionString = BuildConnectionString();
|
var connectionString = BuildConnectionString();
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ namespace Xamarin.Neo4j.ViewModels
|
|||||||
|
|
||||||
Commands.Add("Connect", new Command(async () =>
|
Commands.Add("Connect", new Command(async () =>
|
||||||
{
|
{
|
||||||
// TODO: Validate input.
|
if (!ValidateInput()) return;
|
||||||
|
|
||||||
var connectionString = BuildConnectionString();
|
var connectionString = BuildConnectionString();
|
||||||
|
|
||||||
@@ -103,6 +105,28 @@ namespace Xamarin.Neo4j.ViewModels
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ValidateInput()
|
||||||
|
{
|
||||||
|
// Username and Password not checked because username- and passwordless connections are allowed
|
||||||
|
|
||||||
|
var ipRegex = new Regex(@"\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b");
|
||||||
|
var portRegex = new Regex(@"^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$");
|
||||||
|
|
||||||
|
if (!ipRegex.IsMatch(Host))
|
||||||
|
{
|
||||||
|
UserDialogs.Instance.AlertAsync("Incorrect host format");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!portRegex.IsMatch(Port.ToString()))
|
||||||
|
{
|
||||||
|
UserDialogs.Instance.AlertAsync("Incorrect port format");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#region Bindable Properties
|
#region Bindable Properties
|
||||||
|
|
||||||
public bool Encrypted
|
public bool Encrypted
|
||||||
|
|||||||
Reference in New Issue
Block a user