Пример #1
0
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            string       usernameInput = txtuser.Text;
            string       passwordInput = txtpass.Text;
            Users        userInstance  = new Users();
            List <Users> userlist      = userInstance.PopulateUsers();
            bool         canlogin      = false;

            foreach (Users item in userlist)
            {
                if (item.Username == usernameInput && item.Password == passwordInput)
                {
                    canlogin = true;
                }
                else if (canlogin == true)
                {
                    Form1 form = new Form1();
                    form.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Wrong username and password");
                }
                txtuser.Clear();
                txtpass.Clear();
            }
        }
Пример #2
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();
                }
            }
        }