用户身份验证与 xml.C#.



我正在尝试使用此代码循环它,但我只得到第一个用户名和密码正确,任何其他用户名和密码都是不正确的。这意味着它只是一个用户循环思考。

XmlDocument mac = new XmlDocument();
mac.Load(@"C:Usersusersourcereposlilis shoplilis shopPropertiesXMLFile1.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 循环以检查确切值。

最新更新