Пример #1
0
        // Method which handles the 'Login' button being clicked
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            // A string set up to store the username entered in the textbox 'usernameInput'
            loginUsernameEntered = usernameInput.Text;

            // A string set up to store the password entered in the passwordbox 'passwordInput'
            loginPasswordEntered = passwordInput.Password;

            // An IF statment which handles if the Username exists on the database
            // Calls the DoesThisAccountUsernameExist() method from the Validation class
            // Passes the value stored for the string 'loginUsernameEntered'.
            // Enters the IF statement when the boolean value 'false' is returned
            if (validation.DoesItExist("SELECT * FROM login WHERE Username='******'") == false)
            {
                MessageBox.Show("There is problem with your login details.\n\nPlease try again.");

                // Clears the content of the textbox 'usernameInput'
                usernameInput.Text = "";

                // Clears the content of the passwordbox 'passwordInput'
                passwordInput.Password = "";

                return;
            }

            GetPasswordAndAccountType();

            // An ELSE IF statment which handles if the Username entered and the password entered are the same
            // If they are the same, the application will display a message informing the user that this is the first time that account
            // Has logged in and will have to register the account before being able to use the account further.
            // The user will be navigated to the registration page.
            if (loginUsernameEntered == loginPasswordEntered)
            {
                // The program will only enter this IF statement if the method ValidatePassword() returns false
                // Meaning that the stored password and the entered password do not match.
                if (hashedPassword.IsThePasswordAMatch(loginPasswordEntered, hashedPasswordOfLoginUsername) == false)
                {
                    MessageBox.Show("There is problem with your login details.\n\nPlease try again.");

                    // Clears the content of the textbox 'usernameInput'
                    usernameInput.Text = "";

                    // Clears the content of the passwordbox 'passwordInput'
                    passwordInput.Password = "";

                    return;
                }
                // ELSE if the passwords do match then the program will enter this ELSE
                else
                {
                    // A message to the user informing them that they must register first before being able to login
                    MessageBox.Show("As this is your first time logging in with this account, you will be redirected to the registration page where you can set your username and password.");

                    // Clears the content of the textbox 'usernameInput'
                    usernameInput.Text = "";

                    // Clears the content of the passwordbox 'passwordInput'
                    passwordInput.Password = "";

                    // Instantiate an object of the Registration page
                    Registration registrationPage = new Registration(loginUsernameEntered);

                    // Navigates to the Registration page
                    NavigationService.Navigate(registrationPage);
                }
            }

            // An ELSE statement which handles If the Username is found on the database and when the password does not match the username
            // (This should be the standard log in)
            else
            {
                // The program will only enter this IF statement if the method ValidatePassword() returns false
                // Meaning that the stored password and the entered password do not match.
                if (hashedPassword.IsThePasswordAMatch(loginPasswordEntered, hashedPasswordOfLoginUsername) == false)
                {
                    MessageBox.Show("There is problem with your login details.\n\nPlease try again.");

                    // Clears the content of the textbox 'usernameInput'
                    usernameInput.Text = "";

                    // Clears the content of the passwordbox 'passwordInput'
                    passwordInput.Password = "";

                    return;
                }

                // If the stored password and entered password match then the program will enter this ELSE
                else
                {
                    // The program will only enter this IF statement if the value for the string 'loginAccountType' is set to "Admin"
                    if (loginAccountType == "Admin")
                    {
                        // Instantiate an object of the AdminStart page
                        AdminStart adminPage = new AdminStart();

                        // Navigates to the AdminStart page
                        NavigationService.Navigate(adminPage);
                    }

                    // The program will only enter this ELSE IF statement if the value for the string 'loginAccountType' is set to "Coach"
                    else if (loginAccountType == "Coach")
                    {
                        // Instantiate an object of the CoachStart page
                        CoachStart coachPage = new CoachStart();

                        // Navigates to the CoachStart page
                        NavigationService.Navigate(coachPage);
                    }

                    // The program will only enter this ELSE statement if there has been a problem setting the value for the string 'loginAccountType'
                    else
                    {
                        MessageBox.Show("There has been an error, please try again.");
                        return;
                    }
                }
            }
        }
Пример #2
0
        private void coachBtn_Click(object sender, RoutedEventArgs e)
        {
            CoachStart coachPage = new CoachStart();

            NavigationService.Navigate(coachPage);
        }