Exemplo n.º 1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     sr_User users = new sr_User();
     string UserID=Session["UserID"].ToString();
     string Password = users.GetPassword(UserID);
     try
     {
         string strPwd = TB_OldPassword.Text;
         string oldPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(strPwd, "MD5");
         if (Password != oldPwd)
         {
             Response.Write("<script>alert('旧密码输入有误')</script>");
             TB_OldPassword.Text = "";
             TB_OldPassword.Focus();
             return;
         }
         else if(TB_NewPassword1.Text!=TB_NewPassword2.Text)
         {
             Response.Write("<script>alert('两次输入的新密码不一致,请重新输入')</script>");
             TB_OldPassword.Text = "";
             TB_NewPassword1.Text = "";
             TB_NewPassword2.Text = "";
             TB_OldPassword.Focus();
             return;
         }
         string strPassword = TB_NewPassword1.Text.ToString();
         string newPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword, "MD5");
         if (users.UpdatePassword(newPwd, UserID))
         {
             Response.Write("<script>alert('密码更改成功')</script>");
             TB_OldPassword.Text = "";
             TB_NewPassword1.Text = "";
             TB_NewPassword2.Text = "";
             TB_OldPassword.Focus();
         }
         else
             Response.Write("<script>alert('密码更改失败')</script>");
     }
     catch (Exception ee)
     {
         Console.WriteLine(ee.Message);
     }
 }
Exemplo n.º 2
0
        //编辑更新
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                sr_User users = new sr_User();
                string UserID="";//新的用户ID
                string RoleID="";//用户角色的ID
                string OldID = Session["temp"].ToString();
                Session.Remove("temp");                     //把未更改时 gridview的ID值拿出来后 可以删掉Session["temp"]
                String tempRole = Session["tempRole"].ToString();
                Session.Remove("tempRole");//把gridview的角色Role值拿出来后 可以删掉Session["tempRole"]
                string Password;
                Password = users.GetPassword(OldID);//获得要插进去的密码
                if (tempRole == "教师")
                    RoleID = "ZQUSR4000";
                else if (tempRole == "管理员")
                    RoleID = "ZQUSR3000";
                else if (tempRole == "系统管理员")
                    RoleID = "ZQUSR2000";
                UserID = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();//新的ID

                if (users.Exists(UserID))       //此账号已经存在
                {
                    Response.Write("<script>alert('此账号已被使用,请改为另外账号')</script>");
                    return;
                }
                else //更新账号==插进一条新的信息删除旧的信息
                {
                  //  users.UpdateIDPwd(UserID,RoleID, OldID);    //插进一条新的信息删除旧的信息(必须还要插进去密码)!!
                    users.UpdateIDPwd(UserID, Password, RoleID, OldID);    //更新一条新的信息删除、旧的信息
                }

            }
            catch (Exception ee)
            {
                Response.Write("<script>alert('抱歉更改失败,建议删除此记录重新添加')</script>");
            }
            finally
            {
                GridView1.EditIndex = -1;
                bind();
            }
        }