Ejemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string output = "Incorrect Password!";
            // Create new Login object
            LoginUser user = new LoginUser();

            // Read input
            user.UserName = txtUserName.Text;
            user.Password = txtPassword.Text;

            // Attempt to Log in
            //string result = DataHandler.SysLogin(userName, password);
            int success = DataHandler.HashLogin(user);

            // RegexCheck
            if (RegexCheck.Password(user.Password) == true)
            {
                if (success == (int)SuccessEnum.Success)
                {
                    currentUser = user.UserName;
                    // Call to method to turn on or off login buttons
                    LoginItems("off");
                    lblWelcome.Text = "Welcome, " + user.UserName + "!";
                    output          = "Welcome, " + user.UserName + "!";
                    tabControl1.Show();
                    // Clear UserName and Password
                    txtUserName.Text = "";
                    txtPassword.Text = "";
                }
            }
            // Display Result
            MessageBox.Show(output, "Login");
            // Reset Password txtBox
            txtPassword.Text = "";
        }
Ejemplo n.º 2
0
        private void btnUpdatePassword_Click(object sender, EventArgs e)
        {
            string output = "";
            // Create new Login object
            LoginUser user = new LoginUser();

            DialogResult result = MessageBox.Show("Do you want to update your password?", "Update password?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Check passwords are matching

                if (txtNewPassword.Text == txtConfirmNewPassword.Text)
                {
                    // Update password
                    user.UserName    = currentUser;
                    user.Password    = txtOldPassword.Text;
                    user.NewPassword = txtNewPassword.Text;
                    if (RegexCheck.Password(user.NewPassword) == true)
                    {
                        int success = DataHandler.UpdatePassword(user);
                        if (success == (int)SuccessEnum.Success)
                        {
                            output = "Updated Password!";
                        }
                        else
                        {
                            output = "Failed to update Password!";
                        }
                    }
                    else
                    {
                        output += "Incorrect Password Format!";
                    }

                    // Display result
                    MessageBox.Show(output, "Result");
                    // Reset textboxes
                    txtOldPassword.Text        = "";
                    txtNewPassword.Text        = "";
                    txtConfirmNewPassword.Text = "";
                }
                else
                {
                    MessageBox.Show("New passwords don't match!", "Error");
                }
            }
        }
Ejemplo n.º 3
0
        private void btnNewLogin_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you want to create a new login?", "Create new login?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                string output = "";
                // Check passwords are matching
                if (txtNewUserConfirmPassword.Text == txtNewUserPassword.Text)
                {
                    // Create new LoginUser object
                    LoginUser user = new LoginUser();
                    user.UserName = txtNewUser.Text;
                    user.Password = txtNewUserConfirmPassword.Text;
                    // RegexCheck
                    if (RegexCheck.Password(user.Password) == true)
                    {
                        int success = DataHandler.NewLogin(user);

                        if (success == (int)SuccessEnum.Success)
                        {
                            output += "Added new Login User!";
                        }
                        else
                        {
                            output += "Failed to add a new user!";
                        }
                    }
                    else
                    {
                        output += "Incorrect Password Format!\n4-12 characters.\nLetters and numbers only.";
                    }

                    // Reset textboxes
                    txtNewUser.Text = "";
                    txtNewUserConfirmPassword.Text = "";
                    txtNewUserPassword.Text        = "";
                }
                else
                {
                    output += "Passwords don't match!";
                }
                MessageBox.Show(output, "Result");
            }
        }