如何从互联网下载多个字符串并检查一个字符串是否为真
本文关键字:字符串 一个 是否 检查 串并 下载 互联网 字符 | 更新日期: 2023-09-27 18:33:52
Im 试图从pastbin文件中获取大量用户名和密码,它只允许我抓取一个。任何建议
注意:我希望它读取此格式 用户:通过(输入) 您好:再见等。>>> http://pastebin.com/raw.php?i=LAUx2zxn
private void button1_Click(object sender, EventArgs e)
{
//userinfo - text file should look like: UsernameHere:PasswordHere
WebClient client = new WebClient();
string userinfo = client.DownloadString("http://pastebin.com/raw.php?i=LAUx2zxn");
if (userinfo == username.Text + ":" + password.Text)
{
MessageBox.Show("Successfully logged in as " + username.Text + ".", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
label1.Text = "Welcome, " + username.Text;
label1.Visible = true;
this.Hide();
MainMenu ss = new MainMenu();
ss.Show();
}
else
{
// Login failed, I added my own stuff here.
MessageBox.Show("Invalid account info entered.'n If you want to buy an account msg'n YouRGenetics 'nOn Skype'n Or Click On Buy Account", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
首先,这不是对用户进行身份验证的好方法。但假设你只是为了学习:
WebClient.DownLoadString() 将页面内容作为一个完整的字符串获取。您必须拆分字符串。像这样的东西将适用于您的条件:
bool authenticated = false;
WebClient client = new WebClient();
string userinfoLines = client.DownloadString("http://pastebin.com/raw.php?i=LAUx2zxn");
foreach (string userinfo in userinfoLines.Split(new[] {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries))
{
if (userinfo == username.Text + ":" + password.Text)
{
authenticated = true;
MessageBox.Show("Successfully logged in as " + username.Text + ".", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
label1.Text = "Welcome, " + username.Text;
label1.Visible = true;
this.Hide();
MainMenu ss = new MainMenu();
ss.Show();
break;
}
}
if (!authenticated)
{
// Login failed, I added my own stuff here.
MessageBox.Show("Invalid account info entered.'n If you want to buy an account msg'n YouRGenetics 'nOn Skype'n Or Click On Buy Account", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
试试这个。
var client = new WebClient();
var source = client.DownloadString("http://pastebin.com/raw.php?i=LAUx2zxn");
var data = new List<string>(source.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
if (data.ConvertAll(d => d.ToLower()).Contains(string.Concat("user", ":", "pass")))
{
// Successfully logged in.
}
else
{
// Invalid credentials
}