Monday, 20 May 2013

C# Trying to use StreamWriter and StreamReader to create a login system but it doesn't work?

C# Trying to use StreamWriter and StreamReader to create a login system but it doesn't work?

This is my code:
 public void button1_Click(object sender, EventArgs e)
    {
        bool loggedin = false;
        Form2 form2 = new Form2();
        Form1 form1 = new Form1();
        {

                if ("log.txt".Contains(Username.Text))
                {
                    loggedin = true;
                    MessageBox.Show("Login sucessfully", "Program", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    form1.Hide();
                    form2.Show();
                }

                else
                {

                     MessageBox.Show("Invalid username or password.", "Program", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }

        }
And even though the Log.txt file contains the usernames and passwords I am trying to log into it still isn't working. Any ideas on how to fix this?

No comments:

Post a Comment