Example #1
0
        private void Find_Click(object sender, EventArgs e)
        {
            if (CK == 0)
            {
                string strQuery = " SELECT password " +
                                  " FROM member " +
                                  " WHERE id = @id " +
                                  " AND question = @question " +
                                  " AND answer = @answer; ";

                try
                {
                    using (MySqlConnection conn = new MySqlConnection(strConnString))
                    {
                        conn.Open();
                        //MetroMessageBox.Show(this, $"DB접속성공!!");
                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection  = conn;
                        cmd.CommandText = strQuery;
                        MySqlParameter paramUserId = new MySqlParameter("@id", MySqlDbType.VarChar, 45);
                        paramUserId.Value = TxtID.Text.Trim(); // 공백 넣는 경우가 아주 많기때문에
                        cmd.Parameters.Add(paramUserId);
                        MySqlParameter paramQuestion = new MySqlParameter("@question", MySqlDbType.VarChar, 45);
                        paramQuestion.Value = CboQ.SelectedItem.ToString();
                        cmd.Parameters.Add(paramQuestion);
                        MySqlParameter paramAnswer = new MySqlParameter("@answer", MySqlDbType.VarChar, 45);
                        paramAnswer.Value = txtA.Text.Trim();
                        cmd.Parameters.Add(paramAnswer);

                        //MySqlDataReader reader = cmd.ExecuteReader();
                        //reader.Read();

                        cmd.ExecuteNonQuery();
                        string PW = cmd.ExecuteScalar().ToString();

                        if (string.IsNullOrEmpty(PW))
                        {
                            MessageBox.Show(this, "질문과 답을 정확히 입력하세요", "로그인실패",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            txtA.Text = string.Empty;
                            txtA.Focus();
                            return;
                        }
                        else
                        {
                            //var md5Hash = MD5.Create();
                            //var decryptoPassword = Commons.VerifyMd5Hash(md5Hash, PW);
                            //PW = decryptoPassword;


                            var res = MessageBox.Show("비번을 새로 입력", "새 비번", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (res == DialogResult.Yes)
                            {
                                id = TxtID.Text.Trim();
                                ChangePW();
                            }
                            //joinForm.FormClosed += new FormClosedEventHandler(childForm_Closed);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(TxtID.Text) || string.IsNullOrEmpty(txtA.Text) || TxtID.Text != txtA.Text)
                {
                    MessageBox.Show("새 비번을 정확히 적어주세요");
                    TxtID.Text = txtA.Text = null;
                    TxtID.Focus();
                }
                else
                {
                    string strQuery = " UPDATE omok.member " +
                                      " SET " +
                                      " password = @password " +
                                      " WHERE NO = " +
                                      " (SELECT temp.NO FROM " +
                                      " (SELECT NO " +
                                      " FROM omok.member " +
                                      " WHERE id= @id) as temp); ";

                    using (MySqlConnection conn = new MySqlConnection(strConnString))
                    {
                        conn.Open();
                        //MetroMessageBox.Show(this, $"DB접속성공!!");
                        MySqlCommand cmd = new MySqlCommand();
                        cmd.Connection  = conn;
                        cmd.CommandText = strQuery;
                        MySqlParameter paramPW        = new MySqlParameter("@password", MySqlDbType.VarChar, 45);
                        string         PW             = TxtID.Text.Trim();
                        var            md5Hash        = MD5.Create();
                        var            cryptoPassword = Commons.GetMd5Hash(md5Hash, TxtID.Text.Trim());
                        paramPW.Value = cryptoPassword;

                        MySqlParameter paramid = new MySqlParameter("@id", MySqlDbType.VarChar, 45);
                        paramid.Value = id;

                        cmd.Parameters.Add(paramid);
                        cmd.Parameters.Add(paramPW);
                        cmd.ExecuteNonQuery();
                    }


                    var res = MessageBox.Show("새 비번이 바뀌었습니다.", "비번", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (res == DialogResult.Yes)
                    {
                        Hide();
                        LoginForm loginForm = new LoginForm();
                        loginForm.Show();
                    }
                }
            }
        }
Example #2
0
        private void InsertDataToDB()
        {
            string strQuery = "INSERT INTO member " +
                              " (id, password, question, answer) " +
                              " VALUES " +
                              " (@id, @password, @question, @answer); ";

            if (txtPassword.Text.Trim() != txtPWCHECK.Text.Trim())
            {
                MessageBox.Show("비번이 같지 않습니다.");
                txtPassword.Text = txtPWCHECK.Text = null;
                txtPassword.Focus();
            }

            else if (string.IsNullOrEmpty(txtPassword.Text) ||
                     string.IsNullOrEmpty(txtPWCHECK.Text) || string.IsNullOrEmpty(Txt.Text))
            {
                MessageBox.Show("아이디 비번을 채워주세요.");
                TxtID.Text = txtPassword.Text = txtPWCHECK.Text = null;
                TxtID.Focus();
            }

            else if (CboQ.SelectedIndex == 0 || string.IsNullOrEmpty(txtA.Text))
            {
                MessageBox.Show("질문과 답을 해주세요.");
                CboQ.Focus();
            }



            else
            {
                using (MySqlConnection conn = new MySqlConnection(strConnString))
                {
                    conn.Open();
                    string         PW;
                    MySqlCommand   cmd     = new MySqlCommand(strQuery, conn);
                    MySqlParameter paramId = new MySqlParameter("@id", MySqlDbType.VarChar, 45);
                    paramId.Value = TxtID.Text.Trim().ToString();
                    cmd.Parameters.Add(paramId);
                    MySqlParameter paramPassword = new MySqlParameter("@password", MySqlDbType.VarChar, 45);
                    PW = txtPassword.Text.Trim();
                    var md5Hash        = MD5.Create();
                    var cryptoPassword = Commons.GetMd5Hash(md5Hash, txtPassword.Text.Trim());
                    paramPassword.Value = cryptoPassword;
                    cmd.Parameters.Add(paramPassword);
                    MySqlParameter paramQuestion = new MySqlParameter("@question", MySqlDbType.VarChar, 45);
                    paramQuestion.Value = CboQ.SelectedItem.ToString();
                    cmd.Parameters.Add(paramQuestion);
                    MySqlParameter paramAnswer = new MySqlParameter("@answer", MySqlDbType.VarChar, 45);
                    paramAnswer.Value = txtA.Text.Trim();
                    cmd.Parameters.Add(paramAnswer);
                    cmd.ExecuteNonQuery();
                }

                InsertDataToDB1();
                MessageBox.Show("가입되었습니다.");

                Hide();
                LoginForm loginForm = new LoginForm();
                loginForm.Show();
            }
        }