private void buttonChangePwd_Click(object sender, EventArgs e)
        {
            string oldpwd = txt_oldpwd.Text;
            string newpwd = txt_newPwd.Text;
            //Database Connection
            string pas  = LoginForm.userpasswor;
            string type = LoginForm.usertype;

            if (pas.Equals(txt_oldpwd.Text))
            {
                MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bugbase");
                // MessageBox.Show("password matched");
                MySqlCommand sda = new MySqlCommand("update userdetails set password='******', confirmPassword='******' where username='******'", conn);
                //Open Connection
                conn.Open();
                int rows = sda.ExecuteNonQuery();



                if (rows > 0)
                {
                    MessageBox.Show("Password changed. Please click ok to continue");
                    //Dashboard page
                    if (type == "User")
                    {
                        UserPanel dash = new UserPanel();
                        dash.Show();
                        this.Hide();
                    }
                    else
                    {
                        //Dashboard page
                        ProgrammerPanel pdash = new ProgrammerPanel();
                        pdash.Show();
                        this.Hide();
                    }
                }
                else
                {
                    //Display message
                    MessageBox.Show("Password failed to changed. click ok to continue");
                }
            }
            else
            {
                //Display message
                MessageBox.Show("Old password didnot mathed");
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Username
            string user = textBox_user.Text;
            //Password
            string pass = textBox_pwd.Text;
            //Usertype
            string uType = comboBox_utype.Text.Trim();

            //Database connection
            MySqlConnection conn = new MySqlConnection("server=localhost;user id=root;database=bugbase");

            try
            {
                MySqlDataAdapter adapter = new MySqlDataAdapter("Select count(*) from userdetails where username='******'and password='******' and usertype='" + comboBox_utype.Text + "'", conn);
                DataTable        dt      = new DataTable();
                adapter.Fill(dt);//

                if (user.Equals("") || pass.Equals("") || uType.Equals(""))
                {
                    MessageBox.Show("Fill all the forms", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (dt.Rows[0][0].ToString() == "1")
                {
                    // loggedIn = user;
                    // loggedIN_utype = uType;
                    userpasswor = pass;
                    uname       = user;

                    usertype = uType;
                    switch (uType)
                    {
                    case "Admin":
                    {
                        // Admin Panel
                        //  loggedIN_utype = uType;
                        AdminPanel admin = new AdminPanel();
                        MessageBox.Show("Login was succesful.");
                        admin.Show();
                        this.Hide();

                        break;
                    }

                    //user
                    case "User":
                    {
                        // User Dashboard is displayed
                        UserPanel umenu = new UserPanel();
                        MessageBox.Show("Login was succesful.");
                        umenu.Show();
                        this.Hide();
                        break;
                    }

                    case "Programmer":
                    {
                        //Programmer Dashboard is displayed
                        ProgrammerPanel pmenu = new ProgrammerPanel();
                        MessageBox.Show("Login was succesful.");
                        pmenu.Show();
                        this.Hide();
                        break;
                    }
                    }
                }
                else
                {
                    MessageBox.Show("Username or password is incorrect", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                //Step :CLose Connection
                conn.Close();
            }
        }