Beispiel #1
0
        // Function which prompts user with message box once they click log out.
        private void logoutBtn_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to log out?",
                                "Log Out Dialog",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Information) == DialogResult.Yes)
            {
                // Clear username and password on exit.
                currentUser = null;
                currentPass = null;

                LoginForm loginForm = new LoginForm();

                this.Hide();

                loginForm.StartPosition = FormStartPosition.Manual;
                loginForm.Location      = Location;
                loginForm.Size          = Size;

                loginForm.Show();
            }
        }
Beispiel #2
0
        private void SignUpButtonSignUpForm_Click(object sender, EventArgs e)
        {
            // Get connection string from configuration file.
            var connectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;

            MySqlConnection connection = new MySqlConnection(connectionString);

            connection.Open();

            // SQL queries.
            string query     = "INSERT INTO Users(Username, Password) VALUES(@username, @password)";
            string userQuery = "SELECT count(*) FROM Users WHERE Username = @usernamecheck";

            MySqlCommand cmd             = new MySqlCommand(query, connection);
            MySqlCommand checkUserExists = new MySqlCommand(userQuery, connection);

            checkUserExists.Parameters.AddWithValue("@usernamecheck", usernameTextBoxSignUpForm.Text);

            int UserExists = Convert.ToInt32(checkUserExists.ExecuteScalar());

            // If the username entered is taken already, display a message to the user.
            if (UserExists > 0)
            {
                MessageBox.Show("Username is already in use!\nPlease choose another", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                usernameTextBoxSignUpForm.Clear();
                passwordTextBoxSignUpForm.Clear();
                confirmPasswordTextboxSignUpForm.Clear();
                usernameTextBoxSignUpForm.Focus();
            }
            else
            {
                // Checks for blank text boxes and display a message to the user.
                if (usernameTextBoxSignUpForm.Text == "" || passwordTextBoxSignUpForm.Text == "" || confirmPasswordTextboxSignUpForm.Text == "")
                {
                    MessageBox.Show("Please fill in all details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    return;
                }

                if (passwordTextBoxSignUpForm.Text.Equals(confirmPasswordTextboxSignUpForm.Text))
                {
                    // Add username and password to database.
                    cmd.Parameters.AddWithValue("@username", usernameTextBoxSignUpForm.Text);
                    cmd.Parameters.AddWithValue("@password", passwordTextBoxSignUpForm.Text);

                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Sign up Successful!\n\nHello " + usernameTextBoxSignUpForm.Text + "\n");

                    connection.Close();

                    LoginForm loginForm = new LoginForm();

                    // Close current form and open login form in same position.
                    this.Hide();

                    loginForm.StartPosition = FormStartPosition.Manual;
                    loginForm.Location      = Location;
                    loginForm.Size          = Size;

                    loginForm.Show();
                }
                else
                {
                    // If passwords don't match show message to user.
                    MessageBox.Show("Passwords do not match!");
                    usernameTextBoxSignUpForm.Clear();
                    passwordTextBoxSignUpForm.Clear();
                    confirmPasswordTextboxSignUpForm.Clear();
                }
            }
        }
Beispiel #3
0
        private void deleteAccountBtn_Click(object sender, EventArgs e)
        {
            if (usernameTextBox.Text.Equals(currentUser) && passwordText.Text.Equals(currentPass) && confirmPassword.Text.Equals(currentPass))
            {
                // All conditions met, delete account.

                var             connectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
                MySqlConnection connection       = new MySqlConnection(connectionString);

                string query = "delete from Users where Username='******' and Password='******';";

                if (MessageBox.Show("Are you sure you want to delete your account?\nThis cannot be undone",
                                    "Warning",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    MySqlCommand    cmd = new MySqlCommand(query, connection);
                    MySqlDataReader reader;

                    connection.Open();

                    reader = cmd.ExecuteReader();

                    connection.Close();

                    LoginForm loginForm = new LoginForm();

                    usernameTextBox.Clear();
                    passwordText.Clear();
                    confirmPassword.Clear();

                    MessageBox.Show("Logging out...");

                    this.Hide();

                    loginForm.StartPosition = FormStartPosition.Manual;
                    loginForm.Location      = Location;
                    loginForm.Size          = Size;

                    loginForm.Show();
                }
                else
                {
                    usernameTextBox.Clear();
                    passwordText.Clear();
                    confirmPassword.Clear();
                    usernameTextBox.Focus();
                }
            }
            else if (usernameTextBox.Text == "" || passwordText.Text == "" || confirmPassword.Text == "")
            {
                MessageBox.Show("Please fill in all details", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                usernameTextBox.Clear();
                passwordText.Clear();
                confirmPassword.Clear();
                usernameTextBox.Focus();
            }
            else
            {
                MessageBox.Show("Username or Password incorrect!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                usernameTextBox.Clear();
                passwordText.Clear();
                confirmPassword.Clear();
                usernameTextBox.Focus();
            }
        }