您的位置:首页 > 运维架构 > 网站架构

asp.net网站设计,忘记密码功能的代码实现?

2012-12-27 20:31 721 查看
stringuserID=this.userID.Text.Trim();
stringnewpwd=this.newpwd.Text.Trim();//新密码
stringnewpwda=this.newpwda.Text.Trim();//确认新密码
//数据库连接
stringconn="DataSource=KoBe-PC;InitialCatalog=zujuan;IntegratedSecurity=true";
SqlConnectioncon=newSqlConnection(conn);
//打开数据库
con.Open();
SqlCommandcmmd=newSqlCommand("selectuserIDfrom[user]whereuserID='"+this.userID.Text+"'",con);
//读取数据库里的数据
SqlDataReaderdr=cmmd.ExecuteReader();
if(dr.Read())
{

//取得数据库的数据的值,并进行判断,是否存在此用户
if(dr["userID"].ToString().ToLower()!="")
{
//判断文本框里的值是否为空
if(this.newpwd.Text.Trim()==""&&this.newpwda.Text.Trim()=="")
{
//lable用于显示提示信息
this.Label2.Text="不能为空";
this.Label2.Visible=true;
this.Label3.Text="不能为空";
this.Label3.Visible=true;
this.Label4.Visible=false;
}
//判断两次输入密码是否一致
elseif(this.newpwd.Text.Trim()!=this.newpwda.Text.Trim())
{
//Response.Write("<scriptlanguage='javascript'>alert('两次输入密码不一致,请从新输入!');</script>");
this.Label4.Text="两次输入密码不一致,请从新输入!";
this.Label4.Visible=true;
this.newpwd.Text="";
this.newpwda.Text="";
this.Label2.Visible=false;
this.Label3.Visible=false;
}
//	//判断与原密码是否相同
//elseif(dr["userID"].ToString().ToLower()==this.userID.Text.Trim())
//{
//this.Label5.Text="与原密码相同,请从新输入!";
//this.Label5.Visible=true;
//}
else
{
con.Close();
//修改数据库里的数据
SqlCommandcmd=newSqlCommand("update[user]setpassWord='"+this.newpwd.Text.Trim()+"'whereuserID='"+userID+"'",con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<scriptlanguage='javascript'>alert('密码修改成功,请重新登录!');window.location='Login.aspx';</script>");
}
}
}
else
{
Response.Write("<scriptlanguage=javascript>alert('无该用户!')</script>");
}


其中判断与密码相同那段代码可以不用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐