private void confirmChangeButton_Click_1(object sender, EventArgs e)
        {
            try
            {
                dbConn.Open();
                string     sql       = "SELECT * FROM portalUser WHERE portalUser_ID='" + loginForm.UserID + "'";
                SqlCommand dbCommand = new SqlCommand(sql, dbConn);

                SqlDataReader dbReader = dbCommand.ExecuteReader();

                if (dbReader.HasRows)
                {
                    while (dbReader.Read())
                    {
                        if (currentPasswordTextBox.Text == dbReader["portalPassword"].ToString() && newPasswordTextBox.Text == confirmPassTextBox.Text)
                        {
                            dbConn.Close();
                            string markup = "Update portalUser SET portalPassword = '******' Where portalUser_ID = " + loginForm.UserID + "";;

                            SqlCommand market = new SqlCommand(markup, dbConn);

                            dbConn.Open();
                            market.ExecuteNonQuery();

                            MessageBox.Show("password has been updated");

                            teacherForm teaherPortal = new teacherForm();
                            this.Hide();
                            teaherPortal.ShowDialog();
                            this.Show();

                            break;
                        }
                        if (currentPasswordTextBox.Text == dbReader["portalPassword"].ToString() && newPasswordTextBox.Text != confirmPassTextBox.Text)
                        {
                            MessageBox.Show("NEW PASSWORDS DO NOT MATCH");
                            this.Show();



                            break;
                        }
                        if (currentPasswordTextBox.Text != dbReader["portalPassword"].ToString())
                        {
                            MessageBox.Show("incorrect password");

                            break;
                        }
                    }
                }
                dbReader.Close();
                dbConn.Close();
            }
            catch (Exception a)
            {
                MessageBox.Show(a.Message);
                dbConn.Close();
            }
        }
예제 #2
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            try
            {
                dbConn.Open();
                string     sql       = "SELECT * FROM portalUser WHERE username='******'";
                SqlCommand dbCommand = new SqlCommand(sql, dbConn);

                SqlDataReader dbReader = dbCommand.ExecuteReader();

                if (dbReader.HasRows)
                {
                    while (dbReader.Read())
                    {
                        if (usernameTextBox.Text == dbReader["username"].ToString() && passwordTextBox.Text != dbReader["portalPassword"].ToString())
                        {
                            MessageBox.Show("incorrect login details");
                        }
                        if (dbReader["username"].ToString() == usernameTextBox.Text && dbReader["portalPassword"].ToString() == passwordTextBox.Text && dbReader["accountType"].ToString() == "1")
                        {
                            UserID = dbReader["portalUser_ID"].ToString();
                            MessageBox.Show("Welcome " + dbReader["firstName"].ToString());
                            teacherForm teacher = new teacherForm();
                            this.Hide();
                            passwordTextBox.Text = "";
                            usernameTextBox.Text = "";
                            teacher.ShowDialog();
                            this.Show();

                            break;
                        }
                        if (dbReader["username"].ToString() == usernameTextBox.Text && dbReader["portalPassword"].ToString() == passwordTextBox.Text && dbReader["accountType"].ToString() == "0")
                        {
                            UserID = dbReader["portalUser_ID"].ToString();
                            MessageBox.Show("Welcome " + dbReader["firstName"].ToString());
                            studentForm student = new studentForm();
                            this.Hide();
                            passwordTextBox.Text = "";
                            usernameTextBox.Text = "";
                            student.ShowDialog();
                            this.Show();

                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("incorrect login details");
                }
                dbConn.Close();
                dbReader.Close();
            }
            catch (Exception a)
            {
                MessageBox.Show(a.Message);
                dbConn.Close();
            }
        }