private void btnSubmit_Click(object sender, EventArgs e)
        {
            if ((txtCurrentPassword.Text.Equals("")) || (txtNewPassword.Text.Equals("")))
            {
                MessageBox.Show("One or more fields has been left empty.");
            }
            else
            {

                //Get passwords
                String passwordOld = txtCurrentPassword.Text;
                String passwordNew = txtNewPassword.Text;

                LoginModel loginValidateAttempt = new LoginModel();
                User detailsToCheck = loginValidateAttempt.doLogin(currentUser.getUsername(), passwordOld);

                //If a login attempt does not return null, the attempt was successful
                if (detailsToCheck != null)
                {
                    //If the new password is the same as the old password, we say something
                    if (detailsToCheck.getPassword().Equals(Encryption.calcMD5(passwordNew)))
                    {
                        MessageBox.Show("The password you entered is the same as your old password.");
                    }
                    else
                    {
                        //Then we can change the password
                        UserModel uModel = new UserModel();
                        uModel.updatePassword(passwordNew, currentUser.getUsername());

                        MessageBox.Show("Password successfully changed.");
                        this.Close();
                    }

                }
                else
                {
                    MessageBox.Show("The password you entered does not match your current password.");
                }
            }
        }
Exemple #2
0
        /*
         * Button to attempt the login
         * @AUTHOR: Andrew Davis
         */
        private void cmdLogin_Click(object sender, EventArgs e)
        {
            // Create a LoginModel object to handle the login
            LoginModel loginModel = new LoginModel();

            // Get the user credentials from the form
            String username = txtUsername.Text;
            String password = txtPassword.Text;

            // Attempt the login
            User loggedIn = loginModel.doLogin(username, password);

            // If it was successful, go to the Home Page
            if (loggedIn != null)
            {

                MessageBox.Show("SUCCESS! LOGGED IN AS: " + loggedIn.getFirstName() + " " + loggedIn.getLastName());

                // Create a Home Form
                HomePage homeForm = new HomePage();

                // Set the Current User of the HomePage to be the newly logged in user
                homeForm.setCurrentUser(loggedIn);

                // Show the Home Form
                homeForm.Show();

                // Hide the current form
                this.Hide();

            }
            else
            {
                MessageBox.Show("UNSUCCESSFUL LOGIN");

                // Clear the Password field
                txtPassword.Text = "";
            }
        }