Exemplo n.º 1
0
        /*驗證帳號是否存在*/
        private void txtID_Validating(object sender, CancelEventArgs e)
        {
            lblAlarmId.Visible   = false;
            txtPWD.Enabled       = true;
            txtNewPwd.Enabled    = true;
            txtNewPwdVer.Enabled = true;
            btnSavePwd.Enabled   = true;

            string sId = "";

            sId = txtID.Text;

            if (sId != "")
            {
                if (ClsShareFunc.CheckInDb(ClsShareFunc.DbAdmin(), sId, "modify") == false)
                {
                    if (ClsShareFunc.CheckInDb(ClsShareFunc.DbCom(), sId, "modify") == false)
                    {
                        //兩個db皆無
                        lblAlarmId.Visible   = true;
                        txtPWD.Enabled       = true;
                        txtNewPwd.Enabled    = false;
                        txtNewPwdVer.Enabled = false;
                        btnSavePwd.Enabled   = false;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void btnSavePwd_Click(object sender, EventArgs e)
        {
            string        ID      = txtID.Text;
            string        sPwd    = "";
            string        sPwdVer = "";
            string        sOldPwd = "";
            StringBuilder sbMsg   = new StringBuilder();

            sOldPwd = txtPWD.Text;
            sPwd    = txtNewPwd.Text;
            sPwdVer = txtNewPwdVer.Text;

            /*1.帳號不為空白*/
            if (ID != "")
            {
                //密碼不可以一樣
                if (sOldPwd == sPwd || sOldPwd == sPwdVer)
                {
                    sbMsg.Append("密碼不能與之前相同");
                    MessageBox.Show(sbMsg.ToString());
                    return;
                }
                /*3.密碼輸入相同*/
                if (sPwd == sPwdVer)
                {
                    if (VerAction("修改") == false)
                    {
                        return;
                    }

                    /*4.帳號存在Administrator db*/
                    if (ClsShareFunc.CheckInDb(ClsShareFunc.DbAdmin(), ID, "modify") == true)
                    {
                        /*5.更新密碼*/
                        //using (SqlConnection updateCon = new SqlConnection(ClsShareFunc.DB_SECConnection()))
                        using (SqlConnection updateCon = BioBank_Conn.Class_biobank_conn.DB_SEC_conn())
                        {
                            updateCon.Open();
                            SqlCommand updateCmd = new SqlCommand("update BioAdministratorKeyTbl " +
                                                                  "set chAdministratorKey = '" + GetMD5(sPwdVer) + "',chLastModPwdDT = dbo.GetDateToDate13(getdate())" + " where chUserId = '" + ID + "' ", updateCon);
                            updateCmd.ExecuteNonQuery();

                            MessageBox.Show("密碼修改成功!請重新登入。");
                            InitFrm();
                            updateCon.Close();
                            updateCon.Dispose();
                        }
                    }
                    else
                    {
                        /*4.帳號存在 Common db*/
                        if (ClsShareFunc.CheckInDb(ClsShareFunc.DbCom(), ID, "modify") == true)
                        {
                            /*5.更新密碼*/
                            //using (SqlConnection updateCon = new SqlConnection(ClsShareFunc.DB_SECConnection()))
                            using (SqlConnection updateCon = BioBank_Conn.Class_biobank_conn.DB_SEC_conn())
                            {
                                updateCon.Open();
                                SqlCommand updateCmd = new SqlCommand("update BioCommonLoginTbl " +
                                                                      "set chPassword = '******',chLastModPwdDT = dbo.GetDateToDate13(getdate())" + " where chUserId = '" + ID + "' ", updateCon);
                                updateCmd.ExecuteNonQuery();

                                MessageBox.Show("密碼修改成功!請重新登入。");
                                InitFrm();
                                updateCon.Close();
                                updateCon.Dispose();
                            }
                        }
                        else
                        {
                            MessageBox.Show("查無此帳號!");
                        }
                    }
                }
                else
                {
                    sbMsg.Append("\n密碼不一致。請重新輸入!");
                    MessageBox.Show(sbMsg.ToString());
                }
            }
            else
            {
                MessageBox.Show("請先登入!");
            }
            txtNewPwd.Text    = "";
            txtNewPwdVer.Text = "";
        }
Exemplo n.º 3
0
        /*驗證txtPwd*/
        private void txtPWD_Validating(object sender, CancelEventArgs e)
        {
            lblAlarmPwd.Visible  = false;
            txtNewPwd.Enabled    = true;
            txtNewPwdVer.Enabled = true;
            btnSavePwd.Enabled   = true;

            string sPwd = "";
            string sId  = "";

            sId  = txtID.Text;
            sPwd = txtPWD.Text;

            if (ClsShareFunc.CheckInDb(ClsShareFunc.DbAdmin(), sId, "modify") == false)
            {
                if (ClsShareFunc.CheckInDb(ClsShareFunc.DbCom(), sId, "modify") == true)
                {
                    //Common有
                    string sSQL = "";
                    //using (SqlConnection sCon = new SqlConnection(ClsShareFunc.DB_SECConnection()))
                    using (SqlConnection sCon = BioBank_Conn.Class_biobank_conn.DB_SEC_conn())
                    {
                        sCon.Open();
                        sSQL = "select * from BioCommonLoginTbl (nolock) where chUserId = '" + sId + "' ";
                        SqlCommand    sCmd2  = new SqlCommand(sSQL, sCon);
                        SqlDataReader sRead2 = sCmd2.ExecuteReader();
                        if (sRead2.HasRows == true)
                        {
                            while (sRead2.Read())
                            {
                                sPwd = ClsShareFunc.gfunCheck(sRead2["chPassword"]).ToString().Trim();
                            }
                        }
                        sRead2.Close();
                        sCon.Dispose();
                    }

                    if (sPwd != GetMD5(txtPWD.Text))
                    {
                        //密碼錯誤
                        lblAlarmPwd.Visible  = true;
                        txtNewPwd.Enabled    = false;
                        txtNewPwdVer.Enabled = false;
                        btnSavePwd.Enabled   = false;
                    }
                }
            }
            else
            {
                //Administrator有
                string sSQL2 = "";
                //using (SqlConnection sCon = new SqlConnection(ClsShareFunc.DB_SECConnection()))
                using (SqlConnection sCon = BioBank_Conn.Class_biobank_conn.DB_SEC_conn())
                {
                    sCon.Open();
                    sSQL2 = "select * from BioAdministratorKeyTbl (nolock) where chUserId = '" + sId + "' ";
                    SqlCommand    sCmd  = new SqlCommand(sSQL2, sCon);
                    SqlDataReader sRead = sCmd.ExecuteReader();
                    if (sRead.HasRows == true)
                    {
                        while (sRead.Read())
                        {
                            sPwd = ClsShareFunc.gfunCheck(sRead["chAdministratorKey"]).ToString().Trim();
                        }
                    }
                    sRead.Close();
                }

                if (sPwd != GetMD5(txtPWD.Text))
                {
                    //密碼錯誤
                    lblAlarmPwd.Visible  = true;
                    txtNewPwd.Enabled    = false;
                    txtNewPwdVer.Enabled = false;
                    btnSavePwd.Enabled   = false;
                }
            }
        }