Ejemplo n.º 1
0
        private void btnEnter_Click(object sender, RoutedEventArgs e)
        {
            //2. Set variables equal to text output
            string strUsername = txtUsername.Text;
            string strPassword = txtPassword.Text;

            //2. Check if fields are filled out
            if (strUsername.Length == 0 || strPassword.Length == 0)
            {
                MessageBox.Show("Please enter a username and password.");
                return;
            }

            //3. Check if username already exists
            if (CheckUserName(strUsername) == false)
            {
                txtUsername.Text = "";
                txtPassword.Text = "";
                MessageBox.Show("Username already exists");
                return;
            }

            //4. Instantiate a new instance
            LoginCredentials loginUpdate = new LoginCredentials(strUsername.Trim(), strPassword.Trim());

            //5. Send message box message to allow user to continue
            MessageBoxResult messageBoxResult = MessageBox.Show("Do you want to proceed with user authentication?"
                                                                + Environment.NewLine
                                                                , "Create New User Login"
                                                                , MessageBoxButton.YesNo);

            //6. If 'yes' is selected, append to file, clear contents
            if (messageBoxResult == MessageBoxResult.Yes)
            {
                loginCredential.Add(loginUpdate);
                Append(loginUpdate);
                Clear();
                MessageBox.Show("New User Saved!");
                Login winLogin = new Login();
                winLogin.Show();
                this.Close();
            }
        }