c# - 使用 xml 进行用户身份验证。C#
问题描述
我试图用这段代码循环它,但我只得到第一个用户名和密码正确,其他任何一个都不正确。这意味着它只是循环思考一个用户。
XmlDocument mac = new XmlDocument();
mac.Load(@"C:\Users\user\source\repos\lilis shop\lilis shop\Properties\XMLFile1.xml");
XmlNodeList xnlist = mac.DocumentElement.SelectNodes("//logins//users");
foreach (XmlNode naa in xnlist)
{
string username = naa["/username"].InnerText;
string password = naa["/password"].InnerText;
if (username == txtusername.Text && password == txtpassword.Text)
{
Letsee = "LOGEDIN";
Form1 openform = new Form1();
openform.lablogin.Text = Letsee;
openform.lab1.Text = this.txtusername.Text;
openform.labelsingout.Text = "SINGOUT";
openform.Show();
this.Hide();
break;
}
else
{
MessageBox.Show("please enter the correct password or username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtpassword.Text = null;
txtusername.Text = null;
break;
}
}
解决方案
这可能是空格问题。您必须调试此 foreach 循环以检查确切值。
推荐阅读
- pytorch - Pytorch:参数的梯度保持为0
- c - C - 传递对malloc函数指针的引用?
- c# - 如何使用文件结果在.net core web api中取消正在进行的下载?
- java - 如果我的 searchView 搜索视图中没有任何内容,则显示所有用途为空
- angular - 公共临时 url .Net Core API Angular
- r - 按组更改绘图的 x 轴值和背景颜色
- javascript - 将道具传递到屏幕没有出现拳头时间
- java - Android 过滤“mp3”文件
- databricks - 从 Python 中的 Databricks Filestore 下载 CSV 文件不起作用
- c# - 强制转换为 C# 中的两种类型之一