Hey evryone I am trying to create an IP adress comparison so when the user logs in he/she needs to be tested to see if the IP on mysql database is ip on system's computer
I keep getting error object reference not set to an object, because I do not know how to get users IP from C# i've tried many codes but cannot seem to convert them into int32s
here is my code
private void CheckIf1Login()
{
MySqlConnection conn = new MySqlConnection(myConnection);
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT ip_addr FROM `as_users` WHERE username = '" + Form1.TextBoxText + "'";
conn.Open();
MySqlCommand SelectCommand = new MySqlCommand("SELECT ip_addr'", conn);
int IP2 = Convert.ToInt32(cmd.ExecuteScalar());
string ipAddress = HttpContext.Current.Request.UserHostAddress;
uint IP3 = GetIpAsUInt32(ipAddress);
MessageBox.Show("" + IP3);
if (IP2 == IP3)
{
MessageBox.Show("Whoops! It seems that your package subscribtion has expired, to renew it please click here.");
}
else
{
CheckPackageType();
}
}
public uint GetIpAsUInt32(string ipString)
{
IPAddress address = IPAddress.Parse(ipString);
byte[] ipBytes = address.GetAddressBytes();
Array.Reverse(ipBytes);
return BitConverter.ToUInt32(ipBytes, 0);
}