即使 Log.txt 文件包含我尝试登录的用户名和密码,以下仍然无法正常工作。
这是我的 REMADE 登录代码:
public void button1_Click(object sender, EventArgs e)
{
bool loggedin = false;
Form2 form2 = new Form2();
Form1 form1 = new Form1();
var contents = File.ReadAllLines(@"C:\log.txt");
if (contents.Contains(Username.Text))
{
loggedin = true;
MessageBox.Show("Login sucessfully", "Program", MessageBoxButtons.OK, MessageBoxIcon.Information);
form1.Hide();
form2.Show();
}
else
{
if (loggedin == false)
{
MessageBox.Show("Invalid username or password.", "Program", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
这是我的注册码:
{
using (System.IO.StreamWriter writer = new System.IO.StreamWriter("C:\\log.txt", true))
{
writer.WriteLine("\r" + "Username : " + textBox1.Text);
writer.WriteLine("Password : " + textBox2.Text);
writer.WriteLine("Age : " + textBox4.Text);
}
Form5 form5 = new Form5();
Form1 form1 = new Form1();
form1.Show();
this.Hide();
}
有任何想法吗?