简单的 C# 白名单,查找用户名和过期的问题
Simple C# whitelist, problems with looking up username and expiry
我可能没有写对(我是 C# 新手,哈哈)但我需要 C# whitelist/activation/license 方面的帮助。
因此,如果我在文本框中写入 1111-1111-1111-1111
作为许可证密钥,我会得到 31-12-9999
作为到期时间而不是 Discord#5550
作为用户名,这是预期的但不适用于多行.
我还需要密钥旁边的到期日期和用户名,我正在尝试拆分字符串,但它一次只适用于一行,所以即使我使用 2222-2222-2222-2222
作为密钥,它仍然会得到 Not Discord#5550
作为用户名,这是不应该发生的,应该是 charlootus#3330.
我已经把代码留给你们看和修改了。
白名单(也作为 pastebin,查看代码):
1111-1111-1111-1111|31-12-9999|Not Discord#5550
2222-2222-2222-2222|31-12-9999|charlootus#3330
简化版:
该程序不知道到期日或用户名,它从从 Pastebin 下载的字符串中获取它,并使用输入的密钥搜索相邻的用户名和到期日期,然后进行验证。第二个密钥是从第一行提取到期日和用户名,这本不应该发生。
应该很容易解决,但我环顾四周似乎找不到任何东西。
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace loader
{
// Token: 0x02000002 RID: 2
public partial class entry : Form
{
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
public entry()
{
this.InitializeComponent();
}
// Token: 0x06000002 RID: 2 RVA: 0x00002234 File Offset: 0x00000434
private async void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length != 19)
{
string caption = "License key is not valid.";
string text = "License key is not valid." + Environment.NewLine + Environment.NewLine + "Make sure you enter it in AAAA-BBBB-CCCC-DDDD format.";
MessageBoxButtons buttons = MessageBoxButtons.OK;
if (MessageBox.Show(this, text, caption, buttons, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Submit key";
this.button1.Enabled = true;
}
}
else
{
this.textBox1.Enabled = false;
this.textBox1.Text = this.textBox1.Text.ToUpper();
this.button1.Enabled = false;
string[] array = new string[]
{
"Verifying key.",
"Verifying key..",
"Verifying key...",
};
foreach (string text2 in array)
{
this.button1.Text = text2;
await Task.Delay(new Random().Next(450, 850));
}
string[] array2 = null;
string whitelist = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
string fin = String.Format(this.textBox1.Text);
string[] result = whitelist.Split('|');
string whitelistx = result[0];
string expiry = result[1];
string username = result[2];
if (whitelist.Contains(fin))
{
var date = DateTime.ParseExact(expiry, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var result1 = (date - DateTime.Now.Date).Days;
if (result1 >= 0)
{
string caption2 = "Success!";
if (MessageBox.Show(this, string.Concat(new string[]
{
"License key is valid.",
Environment.NewLine,
Environment.NewLine,
"Hi ", username, "! Key expires on the ", expiry,
Environment.NewLine,
"Restart DeluxeUnban."
}), caption2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
System.IO.File.WriteAllText(@"C:\NVIDIA\username.txt", username);
System.IO.File.WriteAllText(@"C:\NVIDIA\expiry.txt", expiry);
System.IO.File.WriteAllText(@"C:\NVIDIA\license.txt", this.textBox1.Text);
}
Application.Exit();
}
else
{
string caption3 = "License key is not valid";
if (MessageBox.Show(this, "License key has expired.", caption3, MessageBoxButtons.OK, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
}
}
}
else
{
string caption3 = "License key is not valid";
if (MessageBox.Show(this, "License key is incorrect." + Environment.NewLine + Environment.NewLine + "Make sure you didn't enter O instead of 0 (zero) or 1 instead of l (small L)", caption3, MessageBoxButtons.OK, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
}
}
}
}
// Token: 0x06000003 RID: 3 RVA: 0x0000205E File Offset: 0x0000025E
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("link hidden");
}
}
}
您的白名单 包含两行文本。所以你的第一步应该是用新行拆分它
string listOfUsers = whitelist.Split('\n');
您的其余代码可以放在 foreach 或 for 循环中,如下所示:
foreach(var user in ListOfUsers) // thanks to it you will check all users, not only the first one
{
string[] result = user.Split('|');
string whitelistx = result[0];
string expiry = result[1];
string username = result[2];
if (user.Contains(fin))
{
// rest of your code
当然,你可以优化这段代码,但这只是为了回答你关于只检查第一个用户的问题。
这可能是另一种方法,但错误似乎是你为每一行得到的 \r\n
。
我写了几行消除了这个错误并且工作正常,请阅读评论并询问是否有任何不清楚的地方!
/// <summary>
/// Class for a Licence
/// </summary>
class Licence
{
public string sKey { get; set; }
public string sExpiry { get; set; }
public string sName { get; set; }
}
static void Main(string[] args)
{
// Loading the data with a WebClient
WebClient WB = new WebClient();
// Downloads the string
string whitelist = WB.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// List with all licences
List<Licence> licences = new List<Licence>();
// Foreach Row
foreach (string sRow in whitelist.Split('\n'))
{
// Splits the Row
string[] sData = sRow.Split('|');
// Adds the licence data
licences.Add(new Licence
{
sKey = sData[0],
sExpiry = sData[1],
sName = sData[2]
});
}
// User input
string fin = String.Format("2222-2222-2222-2222");
// Gets the licence class for the specific key
Licence lic = licences.Find(o => o.sKey == fin);
// If there a licence found
if (lic != default(Licence))
{
// Uses the licence class for data output
var date = DateTime.ParseExact(lic.sExpiry, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var result1 = (date - DateTime.Now.Date).Days;
if (result1 >= 0)
{
Console.WriteLine(string.Concat(new string[]
{
"License key is valid.",
Environment.NewLine,
Environment.NewLine,
"Hi ", lic.sName, "! Key expires on the ", lic.sExpiry,
Environment.NewLine,
"Restart DeluxeUnban."
}));
}
}
Console.WriteLine("FINISHED");
Console.ReadKey();
}
问题是您一次搜索所有行。您需要拆分换行符并单独搜索每一行。
string data = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// Split on line breaks
var lines = data.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
// Search for license key (might want to change this)
var foundLicense = lines.FirstOrDefault(l => l.StartsWith(fin));
if (foundLicense != null)
{
var values = foundLicense.Split('|');
var whitelist = values[0];
var date = DateTime.ParseExact(values[1], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var username = values[2];
/* ... */
}
我个人会创建一个 class (DTO) 来保存解析文本时的信息。
void Main()
{
string fin = "111";
string data = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// Parse data to DTO-objects
var licenseData = data.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.Split('|'))
.Select(x => new LicenseModel
{
LicenseKey = x[0],
Date = DateTime.ParseExact(x[1], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture),
Username = x[2]
})
.ToList();
// Find matching license
var foundLicense = licenseData.FirstOrDefault(l => l.LicenseKey.StartsWith(fin));
if (foundLicense != null)
{
/* FOUND LICENSE */
}
}
public class LicenseModel
{
public string LicenseKey { get; set; }
public DateTime Date { get; set; }
public string Username { get; set; }
}
我可能没有写对(我是 C# 新手,哈哈)但我需要 C# whitelist/activation/license 方面的帮助。
因此,如果我在文本框中写入 1111-1111-1111-1111
作为许可证密钥,我会得到 31-12-9999
作为到期时间而不是 Discord#5550
作为用户名,这是预期的但不适用于多行.
我还需要密钥旁边的到期日期和用户名,我正在尝试拆分字符串,但它一次只适用于一行,所以即使我使用 2222-2222-2222-2222
作为密钥,它仍然会得到 Not Discord#5550
作为用户名,这是不应该发生的,应该是 charlootus#3330.
我已经把代码留给你们看和修改了。
白名单(也作为 pastebin,查看代码):
1111-1111-1111-1111|31-12-9999|Not Discord#5550
2222-2222-2222-2222|31-12-9999|charlootus#3330
简化版:
该程序不知道到期日或用户名,它从从 Pastebin 下载的字符串中获取它,并使用输入的密钥搜索相邻的用户名和到期日期,然后进行验证。第二个密钥是从第一行提取到期日和用户名,这本不应该发生。
应该很容易解决,但我环顾四周似乎找不到任何东西。
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Net;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace loader
{
// Token: 0x02000002 RID: 2
public partial class entry : Form
{
// Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
public entry()
{
this.InitializeComponent();
}
// Token: 0x06000002 RID: 2 RVA: 0x00002234 File Offset: 0x00000434
private async void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length != 19)
{
string caption = "License key is not valid.";
string text = "License key is not valid." + Environment.NewLine + Environment.NewLine + "Make sure you enter it in AAAA-BBBB-CCCC-DDDD format.";
MessageBoxButtons buttons = MessageBoxButtons.OK;
if (MessageBox.Show(this, text, caption, buttons, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Submit key";
this.button1.Enabled = true;
}
}
else
{
this.textBox1.Enabled = false;
this.textBox1.Text = this.textBox1.Text.ToUpper();
this.button1.Enabled = false;
string[] array = new string[]
{
"Verifying key.",
"Verifying key..",
"Verifying key...",
};
foreach (string text2 in array)
{
this.button1.Text = text2;
await Task.Delay(new Random().Next(450, 850));
}
string[] array2 = null;
string whitelist = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
string fin = String.Format(this.textBox1.Text);
string[] result = whitelist.Split('|');
string whitelistx = result[0];
string expiry = result[1];
string username = result[2];
if (whitelist.Contains(fin))
{
var date = DateTime.ParseExact(expiry, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var result1 = (date - DateTime.Now.Date).Days;
if (result1 >= 0)
{
string caption2 = "Success!";
if (MessageBox.Show(this, string.Concat(new string[]
{
"License key is valid.",
Environment.NewLine,
Environment.NewLine,
"Hi ", username, "! Key expires on the ", expiry,
Environment.NewLine,
"Restart DeluxeUnban."
}), caption2, MessageBoxButtons.OK, MessageBoxIcon.Asterisk) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
System.IO.File.WriteAllText(@"C:\NVIDIA\username.txt", username);
System.IO.File.WriteAllText(@"C:\NVIDIA\expiry.txt", expiry);
System.IO.File.WriteAllText(@"C:\NVIDIA\license.txt", this.textBox1.Text);
}
Application.Exit();
}
else
{
string caption3 = "License key is not valid";
if (MessageBox.Show(this, "License key has expired.", caption3, MessageBoxButtons.OK, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
}
}
}
else
{
string caption3 = "License key is not valid";
if (MessageBox.Show(this, "License key is incorrect." + Environment.NewLine + Environment.NewLine + "Make sure you didn't enter O instead of 0 (zero) or 1 instead of l (small L)", caption3, MessageBoxButtons.OK, MessageBoxIcon.Hand) == DialogResult.OK)
{
this.button1.Text = "Verify license";
this.button1.Enabled = true;
this.textBox1.Enabled = true;
}
}
}
}
// Token: 0x06000003 RID: 3 RVA: 0x0000205E File Offset: 0x0000025E
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("link hidden");
}
}
}
您的白名单 包含两行文本。所以你的第一步应该是用新行拆分它
string listOfUsers = whitelist.Split('\n');
您的其余代码可以放在 foreach 或 for 循环中,如下所示:
foreach(var user in ListOfUsers) // thanks to it you will check all users, not only the first one
{
string[] result = user.Split('|');
string whitelistx = result[0];
string expiry = result[1];
string username = result[2];
if (user.Contains(fin))
{
// rest of your code
当然,你可以优化这段代码,但这只是为了回答你关于只检查第一个用户的问题。
这可能是另一种方法,但错误似乎是你为每一行得到的 \r\n
。
我写了几行消除了这个错误并且工作正常,请阅读评论并询问是否有任何不清楚的地方!
/// <summary>
/// Class for a Licence
/// </summary>
class Licence
{
public string sKey { get; set; }
public string sExpiry { get; set; }
public string sName { get; set; }
}
static void Main(string[] args)
{
// Loading the data with a WebClient
WebClient WB = new WebClient();
// Downloads the string
string whitelist = WB.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// List with all licences
List<Licence> licences = new List<Licence>();
// Foreach Row
foreach (string sRow in whitelist.Split('\n'))
{
// Splits the Row
string[] sData = sRow.Split('|');
// Adds the licence data
licences.Add(new Licence
{
sKey = sData[0],
sExpiry = sData[1],
sName = sData[2]
});
}
// User input
string fin = String.Format("2222-2222-2222-2222");
// Gets the licence class for the specific key
Licence lic = licences.Find(o => o.sKey == fin);
// If there a licence found
if (lic != default(Licence))
{
// Uses the licence class for data output
var date = DateTime.ParseExact(lic.sExpiry, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var result1 = (date - DateTime.Now.Date).Days;
if (result1 >= 0)
{
Console.WriteLine(string.Concat(new string[]
{
"License key is valid.",
Environment.NewLine,
Environment.NewLine,
"Hi ", lic.sName, "! Key expires on the ", lic.sExpiry,
Environment.NewLine,
"Restart DeluxeUnban."
}));
}
}
Console.WriteLine("FINISHED");
Console.ReadKey();
}
问题是您一次搜索所有行。您需要拆分换行符并单独搜索每一行。
string data = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// Split on line breaks
var lines = data.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
// Search for license key (might want to change this)
var foundLicense = lines.FirstOrDefault(l => l.StartsWith(fin));
if (foundLicense != null)
{
var values = foundLicense.Split('|');
var whitelist = values[0];
var date = DateTime.ParseExact(values[1], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture);
var username = values[2];
/* ... */
}
我个人会创建一个 class (DTO) 来保存解析文本时的信息。
void Main()
{
string fin = "111";
string data = new System.Net.WebClient() { Proxy = null }.DownloadString("https://pastebin.com/raw/ai8q5GEA");
// Parse data to DTO-objects
var licenseData = data.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.Split('|'))
.Select(x => new LicenseModel
{
LicenseKey = x[0],
Date = DateTime.ParseExact(x[1], "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture),
Username = x[2]
})
.ToList();
// Find matching license
var foundLicense = licenseData.FirstOrDefault(l => l.LicenseKey.StartsWith(fin));
if (foundLicense != null)
{
/* FOUND LICENSE */
}
}
public class LicenseModel
{
public string LicenseKey { get; set; }
public DateTime Date { get; set; }
public string Username { get; set; }
}