none
edit xml file to verify old password and create a new one

    Question

  • <?xml version="1.0" encoding="utf-8"?>
    <Users>
      <User userID="1" username="person" password="pass123" usertype="Admin" />
      <User userID="2" username="lol" password="lol" usertype="Guest" />
    </Users>

    I've created an XMLFile1.xml and want to link that file to the form below to verify the old password and create a new password.

    1. User will get authenticated on the basis of UserID, old password.
    2. If User enters wrong detatils will get error messages.


    • Edited by ak999 Tuesday, April 4, 2017 7:27 AM
    Tuesday, April 4, 2017 7:07 AM

Answers

  • Hi angadk9,

    Thank you for posting here.

    For your question, please try the following code.

    private void button1_Click(object sender, EventArgs e)
            {
                var xml = XElement.Load(@"C:\Users\v-wezan\Desktop\XMLFile1.xml");
                IEnumerable<XElement> elements = from element in xml.Elements("User")
                                                 select element;
                foreach (var item in elements)
                {
                    if (item.FirstAttribute.NextAttribute.Value == textBox1.Text && item.FirstAttribute.NextAttribute.NextAttribute.Value == textBox2.Text)
                    {
                        item.FirstAttribute.NextAttribute.NextAttribute.Value = textBox3.Text;
                        xml.Save(@"C:\Users\v-wezan\Desktop\XMLFile1.xml");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Error!");
                        break;
                    }
                    
                }
            }

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ak999 Wednesday, April 5, 2017 4:47 AM
    Wednesday, April 5, 2017 3:20 AM
    Moderator

All replies

  • Hi angadk9,

    Please check bellow link, hope this useful for you.

    https://msdn.microsoft.com/en-us/library/2baksw0z(v=vs.110).aspx

    Tuesday, April 4, 2017 8:01 AM
  • Hi angadk9,

    Thank you for posting here.

    For your question, please try the following code.

    private void button1_Click(object sender, EventArgs e)
            {
                var xml = XElement.Load(@"C:\Users\v-wezan\Desktop\XMLFile1.xml");
                IEnumerable<XElement> elements = from element in xml.Elements("User")
                                                 select element;
                foreach (var item in elements)
                {
                    if (item.FirstAttribute.NextAttribute.Value == textBox1.Text && item.FirstAttribute.NextAttribute.NextAttribute.Value == textBox2.Text)
                    {
                        item.FirstAttribute.NextAttribute.NextAttribute.Value = textBox3.Text;
                        xml.Save(@"C:\Users\v-wezan\Desktop\XMLFile1.xml");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Error!");
                        break;
                    }
                    
                }
            }

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by ak999 Wednesday, April 5, 2017 4:47 AM
    Wednesday, April 5, 2017 3:20 AM
    Moderator
  • thank you once again wendy
    Wednesday, April 5, 2017 4:48 AM