Stack Exchange
User Authenticaiton with xml. C#
I am trying to loop though it with this code but I only get the first username and password correct any other one is incorrect. Which means it’s only looping thought one user.
            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;
                }
            }


cant you use a breakpoint to see whats happening during the 2nd loop? Also would be helpful to see the xml

This may be problem of blank space.
You have to debug this foreach loop to check exact value.
