修改密码的核心代码?请给力指导,谢谢

解决方案 »

  1.   

    修改数据库 表里的密码?那直接用update语句啊
      

  2.   


            public static bool UpdateInfo(string name, string pwd)
            {
                bool b = false;
                string sql = "Update AdminInfo Set passwd='"+pwd+" ' where name='" + name + "'";
                try
                {
                    SqlCommand com = new SqlCommand(sql, sqlConn);
                    sqlConn.Open();
                    int i = (Int32)com.ExecuteNonQuery();
                    if (i > 0)
                    {
                        b = true;
                    }
                }
                catch (Exception ex) { }
                finally
                {
                    sqlConn.Close();
                }
                return b;
            }
      

  3.   


            string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txt_OldPwd.Text, "MD5");
            string sql = "Select Top 1 *  From Manager where UserName=@UserName and  password=@password";
            string[] strParam1 ={ "@UserName", "@password" };
            object[] strValue1 ={ Session["MUserName"], password };
            if (!db.SearchTable(sql, strParam1, strValue1))
            {
                ScriptManager.RegisterStartupScript(up1,typeof(UpdatePanel), "d", "alert('错误:旧密码输入不正确!');",true);
                return;
            }
            password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txt_NewPwd1.Text, "MD5");
            sql = "Update Manager Set Password='" + password + "' Where UserName='" + Session["MUserName"] + "'";
            if (db.ExecuteUpdate(sql))
            {
                ScriptManager.RegisterStartupScript(up1, typeof(UpdatePanel), "d", "alert('密码变更成功!');", true);
                return;
            }
            else
            {
                ScriptManager.RegisterStartupScript(up1, typeof(UpdatePanel), "d", "alert('密码变更失败!');", true);
                return;
            }
      

  4.   

     public static bool UpdateInfo(string name, string pwd)
            {
                bool b = false;
                string sql = "Update AdminInfo Set passwd='"+pwd+" ' where name='" + name + "'";
                try
                {
                    SqlCommand com = new SqlCommand(sql, sqlConn);
                    sqlConn.Open();
                    int i = (Int32)com.ExecuteNonQuery();
                    if (i > 0)
                    {
                        b = true;
                    }
                }
                catch (Exception ex) { }
                finally
                {
                    sqlConn.Close();
                }
                return b;
            }