在ASP.net中修改用户密码怎么写代码?

2025-03-07 10:51:45
推荐回答(3个)
回答1:

protected void UpdateBtn_Click(object sender, EventArgs e)
{
if (NewPwd.Text == "" || ReNewPwd.Text == "")
{
Response.Write("");
return;
}
if (NewPwd.Text != ReNewPwd.Text)
{
Response.Write("");
return;
}
string ConnSql = System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
SqlConnection Conn = new SqlConnection(ConnSql);
SqlCommand SelectCom = new SqlCommand("select * from userinfo", Conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
Conn.Open();
string SecPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(NewPwd.Text, "md5");
string SqlUpdate = "update userinfo set u_password='" + SecPwd + "'" + " where u_name='" + UserNameLab.Text + "'";
da.SelectCommand = SelectCom;
da.Fill(ds,"UserName");
SqlCommand UpdateCom = new SqlCommand(SqlUpdate,Conn);
da.UpdateCommand = UpdateCom;
//执行UpdateCommand
da.UpdateCommand.ExecuteNonQuery();
Conn.Close();
Response.Write("");
}

回答2:

protected void btupdateuser_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("data source=(local);initial catalog=database_breakfast;user=sa;pwd=");
if (this.txtmima.Text == Session ["password"].ToString ())
{
if (this.txtnewmima1.Text== this.txtnewmima2.Text)
{
SqlCommand cmd = new SqlCommand("update t_user set password='" +this.txtnewmima2.Text+ "',username='" +this.txtname.Text+ "' where username= '" +Session ["username"].ToString()+ "' and password='" +Session ["password"].ToString()+ "'",cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
Response.Write("");
}
else
{
Response.Write("");
this.txtnewmima1.Text = "";
this.txtnewmima2.Text = "";
}
}
else
{
Response.Write("");
this.txtmima.Text = "";
this.txtnewmima1.Text = "";
this.txtnewmima2.Text = "";
}

回答3:

update把新数据更新到数据库