New to coding!
How can I get my register form to add the user's details instead of rewriting them everytime? And how can I get my log in form to loop through the XML file to find a matching username and password?
The code that I have does 2 things:
- It rewrites the XML file instead of updating it.
- It duplicates data.
Here is my User class:
public class User
{
public string fname;
public string lname;
public string username;
public string password;
public string Fname
{
get { return fname; }
set { fname = value; }
}
public string Lname
{
get { return lname; }
set {lname = value; }
}
public string Username
{
get { return username; }
set { username = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public User() { }
public User (string fname, string lname, string username, string password)
{
this.fname = fname;
this.lname = lname;
this.username = username;
this.password = password;
}
}
Here is the sign up form code:
public partial class sign_up_form : Form
{
public sign_up_form()
{
InitializeComponent();
}
private void btn_create_Click(object sender, EventArgs e)
{
User users = new User();
users.fname = txt_fname.Text;
users.lname = txt_lname.Text;
users.username = txt_username.Text;
users.password = txt_password.Text;
XmlSerializer xs = new XmlSerializer(typeof(User));
using(FileStream fs = new FileStream("Data.xml", FileMode.Create))
{
xs.Serialize(fs, users);
}
}
}
This is the XML file:
<?xml version="1.0"?>
-<User xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<fname>asdf</fname>
<lname>asdf</lname>
<username>asdf</username>
<password>asdf</password>
<Fname>asdf</Fname>
<Lname>asdf</Lname>
<Username>asdf</Username>
<Password>asdf</Password>
</User>
I do not have any code for the log in form but it only has 2 text boxes (user and pass) and a log in button.
Any advice is appreciated.