-1

I want to make a simple game, with a login interface first, when you create your account I want the username, password and level to be stored in login.txt file. Later, when you login, it verifies your level from the file and opens a specific form.

I tried to use

StreamReader sR = new StreamReader("login.txt");
StreamWriter sW = new StreamWriter("login.txt");

It doesn't work.

How can I do it in a simple way?

Braiam
  • 1
  • 11
  • 47
  • 78
cristi.gherghina
  • 311
  • 1
  • 6
  • 18

1 Answers1

1

Use

using(FileStream fs = new FileStream(@"login.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
...
}

FileAccess.ReadWrite allows you to both read and write on the stream and FileShare.ReadWrite allows you to have more than one reader OR writer to the file

So in theory you can have two of these if you wish

PS: I would not use a textfile to do the login credentials of anything.

Murdock
  • 4,352
  • 3
  • 34
  • 63