在ASP.net中修改用户密码怎么写代码?
3个回答
展开全部
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>");
}
{
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>");
}
展开全部
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 = "";
}
{
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 = "";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
update把新数据更新到数据库
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询