Example #1
0
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            string       name         = txtname.Text;
            string       surname      = txtsurname.Text;
            string       username     = txtuser.Text;
            string       password     = txtpass.Text;
            Users        userInstance = new Users();
            List <Users> userlist     = userInstance.PopulateUsers();
            bool         canSignIn    = false;
            Filehandler  fh           = new Filehandler();

            //check values

            foreach (Users item in userlist)
            {
                if (name.Length == 0 || surname.Length == 0 || username.Length == 0 || password.Length == 0)
                {
                    MessageBox.Show("Please provide information for ALL fields", "Registration unsuccessful", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);
                }
                else
                {
                    string userDetails = string.Format("{0}:{1}:{2}:{3}", name, surname, username, password);

                    fh.WriteData("Login.txt", userDetails);//add new user to the textfile;

                    MessageBox.Show("New user has been  registered successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    txtname.Clear();
                    txtsurname.Clear();
                    txtuser.Clear();
                    txtpass.Clear();
                }
            }
        }
Example #2
0
        public List <Users> PopulateUsers()
        {
            List <Users> user = new List <Users>();
            Filehandler  fh   = new Filehandler();

            List <string> data = fh.ReadUsers("Login.txt");

            foreach (string item in data)
            {
                string[] values = item.Split(',');
                user.Add(new Users(values[0], values[1], values[2], values[3]));
            }
            return(user);
        }