密码恢复,不使用ASP.Net成员资格

时间:2011-12-12 01:28:21

标签: asp.net database vb.net sql-server-2008 asp.net-membership

我在使用VB(ASP.NET)

的网站上工作

我想在不使用asp.net中的控件的情况下实现密码恢复代码

我没有使用ASP.Net Membership登录,我有带USER表的MSSQL数据库

我真正需要的是:

当用户忘记密码时,他/她输入电子邮件然后按下按钮提交,然后我必须在用户表中找到此电子邮件,检索用户名和密码,生成新的随机密码,使用新生成的密码更新密码,最后使用用户名和新生成的密码向用户发送电子邮件。

我该怎么做? 请帮我 谢谢

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

SqlConnection objconnection = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
    //objconnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
   // objconnection.Close();
   // lblInfo.Visible = false;
}
protected void Button1_Click(object sender, EventArgs e)
{    
    String strUsername = txtUsername.Text;
    String strPassword = txtCurrentpassword.Text;
    SqlConnection con = new SqlConnection("Data Source=ARUN-PC\\SQLEXPRESS;Initial Catalog=newspaper;Integrated Security=True");
    con.Open();
    //objectcon=new ObjectCon(); 


    SqlCommand objcommand;
    SqlDataReader objdatareader;

    //OleDbCommand cmd = new OleDbCommand("Select Username,Password from Admin", objconnection);
    //OleDbDataReader dr;
    //jcon = new objcon(); 
    objcommand = new SqlCommand("Select Username,Password *from Login", objconnection);
    objdatareader =objcommand.ExecuteReader();
    {
        if (txtUsername.Text ==objdatareader.GetValue(0).ToString())

            if (txtCurrentpassword.Text ==objdatareader.GetValue(1).ToString())
            {
                SqlCommand cmd = new SqlCommand("Update Login set Password='" + txtNewPassword.Text + "' where Username ='" + txtUsername.Text + "'", objconnection);
                cmd.ExecuteNonQuery();
            }
            else
            {

                lblInfo.Visible = true;
            }

        else
        {

            lblInfo.Visible = true;
        }

    }
    con.Close();
}

}