コード例 #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (File.Exists("users.txt"))
            {
                string[] users     = File.ReadAllLines("users.txt");
                bool     userFound = false;

                foreach (string user in users)
                {
                    string[] splitDetails = user.Split('~');

                    string username = splitDetails[0];
                    string password = splitDetails[1];

                    if ((txtBoxUsername.Text == username) && (txtBoxPassword.Text == password))
                    {
                        userFound = true;
                        break;
                    }
                }

                if (userFound)
                {
                    Hide();
                    HomeForm home = new HomeForm();
                    home.Show();
                }
                else
                {
                    MessageBox.Show("User details are incorrect",
                                    "Incorrect details entered");
                }
            }
            else
            {
                MessageBox.Show("No users have been registered", "No users");
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if(File.Exists("users.txt"))
            {
                string[] users = File.ReadAllLines("users.txt");
                bool userFound = false;

                foreach(string user in users)
                {
                    string[] splitDetails = user.Split('~');

                    string username = splitDetails[0];
                    string password = splitDetails[1];

                    if((txtBoxUsername.Text == username) && (txtBoxPassword.Text == password))
                    {
                        userFound = true;
                        break;
                    }
                }

                if(userFound)
                {
                    Hide();
                    HomeForm home = new HomeForm();
                    home.Show();
                }
                else
                {
                    MessageBox.Show("User details are incorrect",
                                    "Incorrect details entered");
                }
            }
            else
            {
                MessageBox.Show("No users have been registered", "No users");
            }
        }