User profile creator that saves information to a .txt file

I’m trying to create a program that will take user input (first, last name, password, re-enter password) and save its information to a file. Then when the program is opened for a second time it asks for a login, checking for the correct password. So far I have this, but when the button is clicked it throws an exception that the file is being used by another process.

private void enterButton_Click(object sender, EventArgs e)
        {
            


            string first = firstBox.Text;
            string last = lastBox.Text;
            string password = passwordBox.Text;
            string reenter = reEnterBox.Text;

            StreamWriter writer = File.CreateText(USER_PROFILE);

            if (String.Equals(password, reenter))
            {
               
                writer.WriteLine(first);
                writer.WriteLine(last);
                writer.WriteLine(password);

                string correct = password; 

                writer.Close();

            }
            
         }

        private void Form1_Load(object sender, EventArgs e)
        {
            StreamReader reader = File.OpenText(USER_PROFILE); 

          
            string first = firstBox.Text;
            string last = lastBox.Text;
            string password = passwordBox.Text;
            string reenter = reEnterBox.Text;
            
            }
    }
}

This doesn’t appear to be Xojo code.

more like “C” or worse… VB.NET code… no wonder it throws an exception! :slight_smile:

Even if this had been Xojo code: why would anyone save a password in the clear? On the Mac side there is the keychain. Does Windows have something similar?

No, it cannot be VB .NET. No braces there. Plain C apparently.

Are you sure that the previous process is not still running? Have you set AutoQuit to True?

Whatever code is actually being run, it’s missing the equivalent of writer.Close();
But this is Mr Riley’s one and only post - doesn’t seem to have been back, so we may never know.

Yes, and the guy joined apparently to post. Strange fellow.

This is C#.

The Form1_Load event opens a file with path defined elsewhere as USER_PROFILE. It then locks the file and does nothing. The file remains locked.

The enterButton_Click event tries to create a file USER_PROFILE which was already locked the moment that Form1 is loaded. Therefore it is obvious that the file is used by another process.

The codes are not complete as the curly brackets do not match up. There is some code omission in the sample so we may never know.

Anyway, wrong forum.