asp.net实现找回密码功能的代码
本文导语: asp.net 找回密码功能的实现代码: 代码示例: protected void Page_Load(object sender, System.EventArgs e) { pnl_question.Visible =false; //将panal中的按钮置为不能,以防误触发 btn_submit.Enabled =false; } //找回密码之验证问题 pri...
asp.net 找回密码功能的实现代码:
protected void Page_Load(object sender, System.EventArgs e)
{
pnl_question.Visible =false;
//将panal中的按钮置为不能,以防误触发
btn_submit.Enabled =false;
}
//找回密码之验证问题
private void btn_submit_Click(object sender, System.EventArgs e)
{
tbx_uid.ReadOnly =true;
if(tbx_answer.Text.ToString ()==Session["uanswer"].ToString())
{
lbl_message.Text ="您的密码是:"+Session["upassword"].ToString ();
}
else
{ //将panel控件可见
pnl_question.Visible =true;
btn_submit.Enabled =true;
lbl_message.Text ="您所回答的问题不正确,请重试!";
}
}
//找回密码
protected void tbx_uid_TextChanged(object sender, System.EventArgs e)
{ //从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的MMS数据库
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
//构造SQL语句,该语句在Users表中检查用户名和密码是否正确
string mysql= "select * from Users where Uid='"+tbx_uid.Text +"'";
//创建Command对象
SqlCommand cm=new SqlCommand (mysql,cn);
//执行ExecuteReader ()方法
SqlDataReader dr=cm.ExecuteReader ();
if(dr.Read ())
{ //将panel控件可见
pnl_question.Visible =true;
//保存当前用户名及用户权限
tbx_question.Text =dr["uquestion"].ToString() ;
//
Session["uanswer"]=dr["uanswer"].ToString();
Session["upassword"]=dr["upassword"].ToString() ;
lbl_message.Text="请您按要求回答问题!";
btn_submit.Enabled =true;
}
else
{
lbl_message.Text ="对不起,输入的用户名有误,请重新输入";
}
}