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

如题所述

protected void UpdateBtn_Click(object sender, EventArgs e)
{
if (NewPwd.Text == "" || ReNewPwd.Text == "")
{
Response.Write("<script language=javascript>alert('新密码不得为空!');</script>");
return;
}
if (NewPwd.Text != ReNewPwd.Text)
{
Response.Write("<script language=javascript>alert('两次输入的密码不同,请重新输入!');</script>");
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("<script language=javascript>alert('密码修改成功,请单击“返回”回到登录面!');</script>");
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-12-28
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("<script language='javascript'>alert('密码修改成功,请重新登陆!');</script>");
}
else
{
Response.Write("<script language='javascript'>alert('两次输入密码不一致,请从新输入!');</script>");
this.txtnewmima1.Text = "";
this.txtnewmima2.Text = "";
}
}
else
{
Response.Write("<script language='javascript'>alert('原密码不正确,请重新输入!');</script>");
this.txtmima.Text = "";
this.txtnewmima1.Text = "";
this.txtnewmima2.Text = "";
}
第2个回答  2011-12-27
update把新数据更新到数据库本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网