コード例 #1
0
        private void AddUserForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            HomeForm    h = new HomeForm();
            AddUserForm a = new AddUserForm();

            h.msRegistration.BackColor = Color.Black;
            h.Refresh();
        }
コード例 #2
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            //ADO CONNECTION
            conn.Open();

            SqlCommand username = new SqlCommand("SELECT USER_USERNAME FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand ID       = new SqlCommand("SELECT USER_ID FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand password = new SqlCommand("SELECT USER_PASSWORD FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand isActive = new SqlCommand("SELECT ISACTIVE FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand FName    = new SqlCommand("SELECT USER_FIRSTNAME FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand LName    = new SqlCommand("SELECT USER_LASTNAME FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand type     = new SqlCommand("SELECT USER_TYPEID FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);
            SqlCommand command  = new SqlCommand("SELECT USER_IMAGE FROM TBL_USERS WHERE USER_USERNAME LIKE '" + txtUsername.Text + "'", conn);

            //CREATE STRING VARIABLES

            string usern  = Convert.ToString(username.ExecuteScalar());
            string USERID = Convert.ToString(ID.ExecuteScalar());
            string pass   = Convert.ToString(password.ExecuteScalar());
            string stat   = Convert.ToString(isActive.ExecuteScalar());
            string FIname = Convert.ToString(FName.ExecuteScalar());
            string LAname = Convert.ToString(LName.ExecuteScalar());
            int    utype  = Convert.ToInt32(type.ExecuteScalar());

            if (utype == 1)
            {
                Control_variables.type = "Admin";
            }
            else if (utype == 2)
            {
                Control_variables.type = "Registrar";
            }
            else
            {
                Control_variables.type = "Staff";
            }
            conn.Close();


            if (txtUsername.Text != "" && txtPassword.Text != "")
            {
                if (txtUsername.Text == "admin" && txtPassword.Text == "admin")
                {
                    Control_variables.username = "******";
                    Control_variables.type     = "Admin";
                    MessageBox.Show("Welcome Administrator");
                    HomeForm h = new HomeForm();
                    txtUsername.Clear();
                    txtPassword.Clear();

                    h.lbUsername.Text    = Control_variables.username;
                    h.lbPosition.Text    = Control_variables.type;
                    h.groupBox1.Visible  = false;
                    h.btnProfile.Visible = false;
                    h.ShowDialog();

                    this.Close();
                }
                else if (txtUsername.Text == usern && txtPassword.Text == pass)
                {
                    ChangePassForm changepass = new ChangePassForm();
                    Control_variables.username = FIname.ToString() + " " + LAname.ToString();
                    if (utype == 1)
                    {
                        Control_variables.type = "Admin";
                    }
                    else if (utype == 2)
                    {
                        Control_variables.type = "Registrar";
                    }
                    else
                    {
                        Control_variables.type = "Staff";
                    }

                    if (stat == "True")
                    {
                        if (pass == "1234")
                        {
                            conn.Open();
                            SqlCommand get_id = new SqlCommand("SELECT USER_ID FROM TBL_USERS WHERE USER_USERNAME='******'", conn);
                            Control_variables.current_id   = Convert.ToInt32(get_id.ExecuteScalar());
                            changepass.lbusername.Text     = Control_variables.username;
                            changepass.UserID.Text         = Control_variables.current_id.ToString();
                            changepass.txtDefaultpass.Text = pass.ToString();

                            txtUsername.Clear();
                            txtPassword.Clear();
                            changepass.ShowDialog();
                            conn.Close();
                        }
                        else
                        {
                            MessageBox.Show("Welcome " + Control_variables.username, "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            HomeForm h = new HomeForm();
                            //MessageBox.Show(Control_variables.namePosition);
                            // GET PICTURE
                            conn.Open();
                            SqlCommand get_pic = new SqlCommand("SELECT USER_IMAGE FROM TBL_USERS WHERE USER_USERNAME LIKE'" + txtUsername.Text + "'", conn);
                            Control_variables.img       = Convert.ToString(get_pic.ExecuteScalar());
                            h.pictureBox2.ImageLocation = Control_variables.img;
                            SqlCommand get_id = new SqlCommand("SELECT USER_ID FROM TBL_USERS WHERE USER_USERNAME LIKE'" + txtUsername.Text + "'", conn);
                            Control_variables.current_id = Convert.ToInt32(get_id.ExecuteScalar());

                            conn.Close();

                            //PASS VARIABLES
                            h.lbUsername.Text = Control_variables.username;
                            h.lbPosition.Text = Control_variables.type;

                            //CLEAR TEXTBOXES
                            txtUsername.Clear();
                            txtPassword.Clear();



                            h.ShowDialog();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Your account is Inactive, contact your Administrator.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        txtPassword.Clear();
                        txtUsername.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect Username and Password!");
                    txtPassword.Clear();
                    txtUsername.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please input Username and Password");
                txtUsername.Focus();
            }
        }
コード例 #3
0
ファイル: ChangePassForm.cs プロジェクト: kinoah2018/ANS_SIS
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (txtuname.Text != "" || txtNewpass.Text != "" || txtRetypepass.Text != "")
            {
                if (txtNewpass.Text != "1234" && txtRetypepass.Text != "1234")
                {
                    if (txtNewpass.Text.Length >= 8)
                    {
                        if (txtNewpass.Text == txtRetypepass.Text)
                        {
                            conn.Open();
                            SqlCommand get_UID  = new SqlCommand("SELECT USER_ID FROM TBL_USERS WHERE USER_USERNAME ='******'", conn);
                            int        get_UID2 = Convert.ToInt32(get_UID.ExecuteScalar());
                            conn.Close();

                            db.SP_CHANGEDEFAULTPASS(get_UID2, txtuname.Text, txtNewpass.Text);
                            db.SP_SECUSAVE(cmbsecq.Text, txtans.Text, get_UID2);
                            if (cmbsecq.SelectedValue != null || txtans.Text != "")
                            {
                                DialogResult dialog = MessageBox.Show("Information successfully changed ! \nDo you want to continue logging in ?", "Congrats !", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                                if (dialog == DialogResult.Yes)
                                {
                                    conn.Open();
                                    SqlCommand Utype = new SqlCommand("SELECT USER_TYPEID FROM TBL_USERS WHERE USER_USERNAME = '******'", conn);
                                    string     type  = Convert.ToString(Utype.ExecuteScalar());
                                    conn.Close();

                                    if (type == "1")
                                    {
                                        HomeForm h = new HomeForm();
                                        conn.Open();
                                        h.pictureBox2.ImageLocation = Control_variables.img;
                                        h.lbUsername.Text           = Control_variables.username;
                                        h.lbPosition.Text           = Control_variables.type;
                                        this.Close();
                                        h.ShowDialog();
                                        conn.Close();
                                    }
                                    else if (type == "2")
                                    {
                                        HomeForm hs = new HomeForm();
                                        conn.Open();
                                        hs.pictureBox2.ImageLocation = Control_variables.img;
                                        hs.lbUsername.Text           = Control_variables.username;
                                        hs.lbPosition.Text           = Control_variables.type;
                                        this.Close();
                                        hs.ShowDialog();
                                        conn.Close();
                                    }

                                    else
                                    {
                                        HomeForm hs = new HomeForm();
                                        conn.Open();
                                        hs.pictureBox2.ImageLocation = Control_variables.img;
                                        hs.lbUsername.Text           = Control_variables.username;
                                        hs.lbPosition.Text           = Control_variables.type;
                                        this.Close();
                                        hs.ShowDialog();
                                        conn.Close();
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Missing Security Question And Answer", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Passwords do not match.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtNewpass.Focus();
                            txtRetypepass.Clear();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Password must be at least 8 characters long.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtNewpass.Clear();
                        txtRetypepass.Clear();
                        txtNewpass.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Please do not use the default password.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtNewpass.Clear();
                    txtRetypepass.Clear();
                    txtNewpass.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please fill out all fields", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnChange_Click(object sender, EventArgs e)
        {
            //int count = 0;
            //var scan = db.VERIFYPASSWORD(UserID.Text, txtDefaultpass.Text);


            //foreach (VERIFYPASSWORDResult user in scan)
            //{
            //    if (txtNewpass.Text == "" || txtRetypepass.Text == "")
            //    {
            //        MessageBox.Show("Please Input New Password");
            //    }
            //    else
            //    {
            //        count++;


            //        if (txtNewpass.Text == txtRetypepass.Text)
            //        {
            //            user.USER_PASSWORD = txtNewpass.Text;
            //            db.CHANGEPASSWORD(lbusername.Text, user.USER_PASSWORD);
            //            TBL_USER user2 = new TBL_USER();
            //            MessageBox.Show("Password Updated Successfully");

            //            //CLEAR TEXTBOXES
            //            txtDefaultpass.Clear();
            //            txtNewpass.Clear();
            //            txtRetypepass.Clear();

            //            MessageBox.Show("Welcome " + Control_variables.username);
            //            LoginForm log = new LoginForm();
            //            log.txtUsername.Clear();
            //            log.txtPassword.Clear();

            //            HomeForm h = new HomeForm();


            //            // GET PICTURE
            //            conn.Open();
            //            SqlCommand command = new SqlCommand("SELECT USER_IMAGE FROM TBL_USER WHERE USER_ID = '" + txtID.Text+ "'", conn);
            //            Control_variables.img = Convert.ToString(command.ExecuteScalar());
            //            h.pictureBox2.ImageLocation = Control_variables.img;
            //            conn.Close();
            //            h.lbUsername.Text = Control_variables.username;
            //            h.lbPosition.Text = Control_variables.namePosition;


            //            h.ShowDialog();

            //            this.Close();

            //        }
            //        else
            //        {
            //            MessageBox.Show("Password did not match");
            //        }

            //    }


            //}
            //if (count == 0)
            //{
            //    MessageBox.Show("Account does not Exist");
            //}

            if (txtNewpass.Text != "" && txtRetypepass.Text != "")
            {
                if (txtNewpass.Text != "1234" && txtRetypepass.Text != "1234")
                {
                    if (txtNewpass.Text.Length >= 8)
                    {
                        if (txtNewpass.Text == txtRetypepass.Text)
                        {
                            //textBox1.Text = "UPDATE TBL_USER SET USER_PASSWORD = '******' WHERE USER_ID LIKE'" + txtID.Text + "'";
                            conn.Open();
                            SqlCommand updatePass = new SqlCommand("UPDATE TBL_USERS SET USER_PASSWORD = '******' WHERE USER_ID ='" + UserID.Text + "'", conn);
                            updatePass.ExecuteNonQuery();
                            conn.Close();
                            DialogResult dialog = MessageBox.Show("Password successfully changed ! \nDo you want to continue logging in ?", "Congrats !", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (dialog == DialogResult.Yes)
                            {
                                conn.Open();
                                SqlCommand username = new SqlCommand("SELECT USER_USERNAME FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);
                                SqlCommand password = new SqlCommand("SELECT USER_PASSWORD FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);
                                SqlCommand userStat = new SqlCommand("SELECT ISACTIVE FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);
                                SqlCommand FName    = new SqlCommand("SELECT USER_FIRSTNAME FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);
                                SqlCommand LName    = new SqlCommand("SELECT USER_LASTNAME FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);
                                SqlCommand position = new SqlCommand("SELECT USER_POSITION FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);
                                SqlCommand command  = new SqlCommand("SELECT USER_IMAGE FROM TBL_USERS WHERE USER_ID LIKE '" + UserID.Text + "'", conn);

                                //CREATE STRING VARIABLES

                                string usern  = Convert.ToString(username.ExecuteScalar());
                                string pass   = Convert.ToString(password.ExecuteScalar());
                                string stat   = Convert.ToString(userStat.ExecuteScalar());
                                string FIname = Convert.ToString(FName.ExecuteScalar());
                                string LAname = Convert.ToString(LName.ExecuteScalar());
                                string post   = Convert.ToString(position.ExecuteScalar());

                                conn.Close();
                                HomeForm h = new HomeForm();

                                // GET PICTURE
                                conn.Open();
                                SqlCommand get_pic = new SqlCommand("SELECT USER_IMAGE FROM TBL_USER WHERE USER_ID='" + UserID.Text + "'", conn);
                                Control_variables.img       = Convert.ToString(get_pic.ExecuteScalar());
                                h.pictureBox2.ImageLocation = Control_variables.img;

                                h.lbUsername.Text = Control_variables.username;
                                h.lbPosition.Text = Control_variables.type;
                                this.Close();
                                h.ShowDialog();
                                conn.Close();
                            }
                            else
                            {
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Passwords do not match.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtNewpass.Focus();
                            txtRetypepass.Clear();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Password must be at least 8 characters long.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtNewpass.Clear();
                        txtRetypepass.Clear();
                        txtNewpass.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Please do not use the default password.", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtNewpass.Clear();
                    txtRetypepass.Clear();
                    txtNewpass.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please fill out all fields", "Ooops !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }