So I'm developing software in c#, and I use WHMCS as my license provider. So is there anyway of making c# check if the license is valid?
I have made a form with a text box (where users will input there license key from WHMCS), and I now need it to check if it is valid.
If it is, the program will give a msg.box and if it is not valid, it will give another msg.box
Can someone help?
This is currently the code I have:
public bool TryCn(string KeyNr, string KeyActive)
{
// check sql data base
MySqlConnection con = new MySqlConnection("server=localhost;user=username;pa ssword=password;database=keys;");
MySqlCommand cmd = new MySqlCommand("SELECT * FROM user_keys WHERE user_key = '" + KeyNr + "' AND user_active ='" + KeyActive + "';");
cmd.Connection = con;
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() != false)
{
if (reader.IsDBNull(0) == true)
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
return false;
}
else
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
return true;
}
}
else
{
return false;
}
}
private void login_Click(object sender, EventArgs e)
{
if (TryCn(KeyBox.Text, ActiveBox.Text) == true)
{
VersionCheck form_launch = new VersionCheck();
form_launch.ShowDialog();
this.Close();
}
else
{
string KeyNr = KeyBox.Text;
string KeyActive = ActiveBox.Text;
MessageBox.Show("Your key (" + KeyNr + ") was invalid or not active. \nPlease check if it is the correct key or you need to buy another month.", "WarZ Hack - Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AboutLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
AboutForm form_about = new AboutForm();
form_about.ShowDialog();
}
private void LoginForm_Load(object sender, EventArgs e)
{
}
private void KeyBox_TextChanged(object sender, EventArgs e)
{
}
}
I have made a form with a text box (where users will input there license key from WHMCS), and I now need it to check if it is valid.
If it is, the program will give a msg.box and if it is not valid, it will give another msg.box
Can someone help?
This is currently the code I have:
public bool TryCn(string KeyNr, string KeyActive)
{
// check sql data base
MySqlConnection con = new MySqlConnection("server=localhost;user=username;pa ssword=password;database=keys;");
MySqlCommand cmd = new MySqlCommand("SELECT * FROM user_keys WHERE user_key = '" + KeyNr + "' AND user_active ='" + KeyActive + "';");
cmd.Connection = con;
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() != false)
{
if (reader.IsDBNull(0) == true)
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
return false;
}
else
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
return true;
}
}
else
{
return false;
}
}
private void login_Click(object sender, EventArgs e)
{
if (TryCn(KeyBox.Text, ActiveBox.Text) == true)
{
VersionCheck form_launch = new VersionCheck();
form_launch.ShowDialog();
this.Close();
}
else
{
string KeyNr = KeyBox.Text;
string KeyActive = ActiveBox.Text;
MessageBox.Show("Your key (" + KeyNr + ") was invalid or not active. \nPlease check if it is the correct key or you need to buy another month.", "WarZ Hack - Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AboutLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
AboutForm form_about = new AboutForm();
form_about.ShowDialog();
}
private void LoginForm_Load(object sender, EventArgs e)
{
}
private void KeyBox_TextChanged(object sender, EventArgs e)
{
}
}