亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

簡單的 C# 白名單,查找用戶名和到期日的問題

簡單的 C# 白名單,查找用戶名和到期日的問題

C#
忽然笑 2022-08-20 17:01:38
我可能沒有寫正確(我是C#lol的新手),但我需要C#白名單/激活/許可證方面的幫助。因此,如果我在文本框中寫為許可證密鑰,我會得到到期而不是用戶名,這是預期的,但不適用于多行。1111-1111-1111-111131-12-9999Discord#5550我需要到期日期和用戶名,以及就在密鑰旁邊,我正在嘗試拆分字符串,但它一次只適用于一行,所以即使我用作密鑰,它仍然會得到不是用戶名,這是不應該發生的,應該是2222-2222-2222-2222Discord#5550charlootus#3330.我已經把代碼留給你們看和修復。白名單(也作為粘貼bin,在代碼中查找):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;                }            }
查看完整描述

3 回答

?
守著星空守著你

TA貢獻1799條經驗 獲得超8個贊

這可能是另一種方法,但錯誤似乎是您為每行新行獲得的錯誤。\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();

}


查看完整回答
反對 回復 2022-08-20
?
倚天杖

TA貢獻1828條經驗 獲得超3個贊

問題是您一次搜索所有行。您需要在換行符上進行拆分并單獨搜索每行。


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];

    /* ...  */

}

就個人而言,我會創建一個類(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; }

}


查看完整回答
反對 回復 2022-08-20
?
陪伴而非守候

TA貢獻1757條經驗 獲得超8個贊

您的白名單包含兩行文本。所以你的第一步應該是按新行拆分它


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

當然,您可以優化此代碼,但這只是為了回答有關僅檢查第一個用戶的問題。


查看完整回答
反對 回復 2022-08-20
  • 3 回答
  • 0 關注
  • 118 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號