Esempio n. 1
0
 protected void btnAccept_Click(object sender, EventArgs e)
 {
     //取得客户输入的验证码
     string strCode = txtCode.Text;
     //之前生成的验证码已经过期或不存在
     object strCode2 = Session["check_code"];
     if (strCode2 == null || strCode.ToString().ToLower() != strCode2.ToString().ToLower())
     {
         //显示验证码输入错误
         ydAlertMessage.AlertMessage("验证码输入错误或已经过期,请重新输入!");
         txtCode.Text = "";
         txtOldPwd.Focus();
         return;
     }
     else
     {
         //更换验证码为随机数
         Session["check_code"] = (new Random()).Next().ToString();
     }
     //实例化更新用户表的类
     var da = new t_userTableAdapter();
     //获取用户id
     Int16 id = Int16.Parse(ddlUser.SelectedValue);
     //获取用户输入的旧密码
     string oldPwd = ydPublicMethod.GetMd5(ydPublicMethod.GetMd5(txtOldPwd.Text));
     //用户输入的新密码
     string newPwd = ydPublicMethod.GetMd5(ydPublicMethod.GetMd5(txtNewPwd.Text));
     //待返回的值
     string strError = string.Empty;
     //执行更新
     if (da.UpdateUserPwdByUserIdAndPwd(newPwd, id, oldPwd) > 0)
     {
         ydAlertMessage.AlertMessage("修改成功");
         //将导向的网页路径
         Response.Redirect("~/Shared/Success.aspx?msg=修改密码成功!", true);
     }
     else
     {
         ydAlertMessage.AlertMessage("修改失败!可能旧密码不正确!");
     }
 }