Example #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            String UserPW = "";

            if (TB_NewPW.Text.Length < 6)
                ShowMessage("密碼最少六個位!", MessagePanel, TB_NewPW);
            else if (TB_ConfirmPW.Text.Length < 6)
                ShowMessage("密碼最少六個位!", MessagePanel, TB_ConfirmPW);
            else if (TB_NewPW.Text.Equals(""))
                ShowMessage("請輸入新密碼!", MessagePanel, TB_NewPW);
            else if (TB_ConfirmPW.Text.Equals(""))
                ShowMessage("請輸入確認密碼!", MessagePanel, TB_ConfirmPW);
            else if (!TB_NewPW.Text.Equals(TB_ConfirmPW.Text))
            {
                ShowMessage("新密碼及確認密碼不相符!", MessagePanel, TB_NewPW);
            }
            else
            {
                String sql = "select shop_pw from rps_shopinfo where shop_id = '" + this.user.ID + "'";
                Database db = new Database("rpsdb", sql, Database.WebConfig);
                SqlDataReader reader = db.GetReader();

                while (reader.Read())
                    UserPW = reader["shop_pw"].ToString();

                db.Close();
                if (UserPW.Equals(Cryptography.MD5(TB_NewPW.Text)))
                {
                    ShowMessage("不能使用舊密碼!請更改!", MessagePanel, TB_NewPW);
                    TB_NewPW.Text = String.Empty;
                    TB_ConfirmPW.Text = String.Empty;
                }
                else
                {
                    String HashPW = Cryptography.MD5(TB_NewPW.Text);
                    String ShopID = user.ID;
                    sql = "update rps_shopinfo set shop_first = 'F', shop_pw = '" + HashPW + "' " +
                          "where shop_id = '" + ShopID + "'";
                    db = new Database("rpsdb", sql, Database.WebConfig);
                    db.ExecuteSql(sql);
                    db.Close();
                    String script = "alert('密碼成功更新!'); location.replace('/Main.aspx');";
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", script, true);
                }
            }
        }
 protected void Button1_Click(object sender, EventArgs e)
 {
     if (TB_NewPassword.Text.Length < 6)
         ShowMessage("密碼最少六個位!", MessagePanel, TB_NewPassword);
     else if (TB_ConfirmPassword.Text.Length < 6)
         ShowMessage("密碼最少六個位!", MessagePanel, TB_ConfirmPassword);
     else if (TB_OldPassword.Text.Equals(""))
         ShowMessage("請輸入舊密碼!", MessagePanel, TB_OldPassword);
     else if (TB_NewPassword.Text.Equals(""))
         ShowMessage("請輸入新密碼!", MessagePanel, TB_NewPassword);
     else if (TB_ConfirmPassword.Text.Equals(""))
         ShowMessage("請輸入確認密碼!", MessagePanel, TB_ConfirmPassword);
     else if (!TB_ConfirmPassword.Text.Equals(TB_NewPassword.Text))
     {
         ShowMessage("新密碼與確認密碼不吻合!", MessagePanel, TB_NewPassword);
         TB_NewPassword.Text = "";
         TB_ConfirmPassword.Text = "";
     }
     else if (!this.user.ValidatePassword(TB_OldPassword.Text))
     {
         ShowMessage("舊密碼不正確!", MessagePanel, TB_OldPassword);
     }
     else
     {
         MessagePanel.Text = "&nbsp;";
         try
         {
             String HashPW = Cryptography.MD5(TB_NewPassword.Text);
             String sql = "update rps_shopinfo set shop_pw = '" + HashPW + "' where shop_id = '" + user.ID + "'";
             Database db = new Database("rpsdb", sql, Database.WebConfig);
             db.ExecuteSql(sql);
             MessagePanel.Text = "&nbsp;";
             TB_OldPassword.Text = "";
             TB_NewPassword.Text = "";
             TB_ConfirmPassword.Text = "";
             String script = "alert('密碼成功更新!'); location.replace('/Main.aspx');";
             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", script, true);
         }
         catch (Exception)
         {
             String script = "alert('密碼更新失敗!'); location.replace('/Main.aspx');";
             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", script, true);
         }
     }
 }