如何从数据库中找到忘记的密码?

时间:2013-03-18 06:41:00

标签: c# asp.net sendmail 3-tier

我有一个项目,我想发送忘记密码邮件,但我无法从数据库中找到用户名和密码,它发送空白邮件,如UserName:和密码:我想找到用户名和密码来自3层架构中的数据基础提前感谢,这是我的代码......

 protected void Button1_Click(object sender, EventArgs e)
    {
        int id = MyRegistration.fgusername(txt_Email.Text.Trim());
        if (id > 0)
        {
            string sQuery = "Select UserName, Password From Registration Where EmailID = '" + txt_Email.Text + "'";

            DataSet ds =DataAccessLayer.ExeSelectQuery(sQuery);
            try
            {
                string sUserName = "";
                string sPassword = "";
                sendMail( sUserName, sPassword);
            }
            catch (Exception ex) { }
        }
        else { label1.Text = "Invalid User"; }
    }

数据访问层:

  public static int fgusername(string sEmailId)
        {
            int id1 = 0;
            string selectstr = "SELECT UserName, Password FROM Registration WHERE EmailID = '" + sEmailId.Trim() + "'";
            id1 = DataAccessLayer.ExecuteReader(selectstr);
            return id1;
        }

4 个答案:

答案 0 :(得分:1)

运行此代码还有什么期望

string sUserName = "";
            string sPassword = "";
            sendMail( sUserName, sPassword);


try
        {
            string sUserName = "";
            string sPassword = "";
            sendMail( sUserName, sPassword);
        }
        catch (Exception ex) { throw ex; // throw the exception }

答案 1 :(得分:1)

DataSet ds =DataAccessLayer.ExeSelectQuery(sQuery);
            try
            {

  if(ds .Tables[0].Rows.Count>0)
                {
  string sUserName = "";
                string sPassword = "";
                 sUserName =   ds.Tables[0].Rows[0]["Username"].ToString();
                 sPassword =   ds.Tables[0].Rows[0]["Password"].ToString();
sendMail( sUserName, sPassword);
                } 
            }

嗨试试这个希望它会帮助你..

答案 2 :(得分:0)

您在发送邮件之前将用户名和密码设置为空,请参阅以下内容:

string sUserName = "";
string sPassword = "";

sendMail( sUserName, sPassword);

尝试这样做:

string sUserName = ds.Tables[0].Rows[0]["UserName"].ToString();
string sPassword = ds.Tables[0].Rows[0]["Password"].ToString();

sendMail( sUserName, sPassword);

答案 3 :(得分:0)

string sUserName =“”; string sPassword =“”; 你初始化这两个变量没有值,我认为你的SendMail(sUserName,sPassword);正在使用这些变量值。