Post: C# Serial Key Help
08-30-2015, 05:15 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); So im making a program that requires serial keys.
I got it to read the serial keys but i want it so it reads to see if the key is banned.

the txt file has keys in every line but i want it to be like
    EXAMPLE:
key:NotBanned
1337:Banned


This is my code:
    
private void button3_Click(object sender, EventArgs e)
{
if (keyBOX.Text != "")
{
if (isValid(keyBOX.Text))
{
MessageBox.Show("Valid key!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Invalid key!", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Enter a key!", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

public bool isValid(string key)
{
if(String.IsNullOrEmpty(key))
{
return false;
}
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("the txt file").Split('\n'Winky Winky)
if (mKey == key) return true;
return false;
}
}


I hope someone can help me with the ban system Smile

Sincerly, MrMods.
(adsbygoogle = window.adsbygoogle || []).push({});
08-30-2015, 06:20 PM #11
Scouse Power
Knowledge is power
Originally posted by xMrMods View Post
Theres a bug on it.
When the key is banned it says banned but then it says invalid.

    
private void flatButton3_Click(object sender, EventArgs e)
{
if (keyBOX.Text != "")
{
if (isValid(keyBOX.Text))
{
MessageBox.Show("Valid key!", title, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Visible = false;
Form1 main = new Form1();
main.Visible = true;
}
else
{
MessageBox.Show("Invalid key!", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("Enter a key!", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public bool isValid(string Key)
{
if (String.IsNullOrEmpty(Key)) return false;
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("site").Split('\n'Winky Winky)
{
string[] mBits = mKey.Split('|'Winky Winky;
if (mBits.Length == 2)
{
MessageBox.Show("Reason for ban:\n\n" + mBits[1]);
return false;
}
if (mKey == Key) return true;
}
}
return false;
}


Obliviously lmao? It's not going to be valid if it's banned. That's not a bug. However, here you go a "fixed" version lol.

    public KeyValuePair<bool, string> isValid(string Key)
{
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("yoursite").Split('\n'Winky Winky)
{
string[] mBits = mKey.Split('|'Winky Winky;
if(mBits.Length == 2)
return new KeyValuePair<bool, string>(false, mBits[2]);
if (mKey == Key)
return new KeyValuePair<bool, string>(true, "You have successfully been logged in.");
}
}
return new KeyValuePair<bool, string>(false, "Invalid key.");
}

public void exampleCall()
{
var Licence = isValid("ExampleKey");
MessageBox.Show(Licence.Value);
if (Licence.Key)
{
//do what you want if key is valid, errors are handled for you.
}
}
08-30-2015, 06:24 PM #12
Originally posted by StackOverflow View Post
Obliviously lmao? It's not going to be valid if it's banned....


Like if the key is banned it says banned and then it says invalid right after.
How can i make it only say banned?
08-30-2015, 06:26 PM #13
Scouse Power
Knowledge is power
Originally posted by xMrMods View Post
Like if the key is banned it says banned and then it says invalid right after.
How can i make it only say banned?


I edited the original post.
    public KeyValuePair<bool, string> isValid(string Key)
{
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("yoursite").Split('\n'Winky Winky)
{
string[] mBits = mKey.Split('|'Winky Winky;
if(mBits.Length == 2)
return new KeyValuePair<bool, string>(false, mBits[2]);
if (mKey == Key)
return new KeyValuePair<bool, string>(true, "You have successfully been logged in.");
}
}
return new KeyValuePair<bool, string>(false, "Invalid key.");
}

public void exampleCall()
{
var Licence = isValid("ExampleKey");
MessageBox.Show(Licence.Value);
if (Licence.Key)
{
//do what you want if key is valid, errors are handled for you.
}
}
08-30-2015, 06:32 PM #14
Originally posted by StackOverflow View Post
I edited the original post.
    public KeyValuePair<bool, string> isValid(string Key)
{
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("yoursite").Split('\n'Winky Winky)
{
string[] mBits = mKey.Split('|'Winky Winky;
if(mBits.Length == 2)
return new KeyValuePair<bool, string>(false, mBits[2]);
if (mKey == Key)
return new KeyValuePair<bool, string>(true, "You have successfully been logged in.");
}
}
return new KeyValuePair<bool, string>(false, "Invalid key.");
}

public void exampleCall()
{
var Licence = isValid("ExampleKey");
MessageBox.Show(Licence.Value);
if (Licence.Key)
{
//do what you want if key is valid, errors are handled for you.
}
}


i got a error on
    
return new KeyValuePair<bool, string>(false, mBits[2]);


this is what i have
    
private void flatButton3_Click(object sender, EventArgs e)
{
if (keyBOX.Text != "")
{
exampleCall();
}
else
{
MessageBox.Show("Enter a key!", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public KeyValuePair<bool, string> isValid(string Key)
{
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("site").Split('\n'Winky Winky)
{
string[] mBits = mKey.Split('|'Winky Winky;
if (mBits.Length == 2)
return new KeyValuePair<bool, string>(false, mBits[2]);
if (mKey == Key)
return new KeyValuePair<bool, string>(true, "You have successfully been logged in.");
}
}
return new KeyValuePair<bool, string>(false, "Invalid key.");
}

public void exampleCall()
{
var Licence = isValid(keyBOX.Text);
MessageBox.Show(Licence.Value);
if (Licence.Key)
{
//do what you want if key is valid, errors are handled for you.
}
}
08-30-2015, 06:44 PM #15
Scouse Power
Knowledge is power
Originally posted by xMrMods View Post
i got a error on
    
return new KeyValuePair<bool, string>(false, mBits[2]);


this is what i have
    
private void flatButton3_Click(object sender, EventArgs e)
{
if (keyBOX.Text != "")
{
exampleCall();
}
else
{
MessageBox.Show("Enter a key!", title, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public KeyValuePair<bool, string> isValid(string Key)
{
using (WebClient wb = new WebClient())
{
foreach (string mKey in wb.DownloadString("site").Split('\n'Winky Winky)
{
string[] mBits = mKey.Split('|'Winky Winky;
if (mBits.Length == 2)
return new KeyValuePair<bool, string>(false, mBits[2]);
if (mKey == Key)
return new KeyValuePair<bool, string>(true, "You have successfully been logged in.");
}
}
return new KeyValuePair<bool, string>(false, "Invalid key.");
}

public void exampleCall()
{
var Licence = isValid(keyBOX.Text);
MessageBox.Show(Licence.Value);
if (Licence.Key)
{
//do what you want if key is valid, errors are handled for you.
}
}


change mBits[2] to mBits[1] - my bad.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo