【问题标题】:How to find forgot password from the database?如何从数据库中找到忘记的密码?
【发布时间】:2013-03-06 10:44:41
【问题描述】:

我有一个项目,我想在其中发送忘记密码的邮件,但我无法从数据库中找到用户名和密码,它正在发送空白邮件,如用户名:和密码:我想从中查找用户名和密码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;
        }

【问题讨论】:

  • 在发送邮件之前,您只需将 sUserName 和 sPassword 设置为空白。
  • 危险:SQL 注入! ;-)
  • 如何从选择用户名和密码的查询中接收 ID? (检查fgusername方法)
  • 真的以明文形式存储密码吗?

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


【解决方案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】:

    运行此代码您还期望什么

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

    【讨论】:

    • mail.Body = "Hi, <br/>Please check your Login Details<br/><br/>UserName: " + sUserName + "<br><br>Password: " + sPassword + "<br><br>"; mail.IsBodyHtml = true;
    【解决方案3】:

    您在发送邮件之前将 sUsername 和 sPassword 设置为空,如下所示:

    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);
    

    【讨论】:

    • 这是因为您正在破坏 stacktrace ,因此您会遇到异常,以便您可以了解未收到电子邮件的原因以及如何做到这一点,请参阅下面的答案。
    • @yash : 我刚刚给你核心代码,你必须做的基本检查,你可以检查上面的代码和我的代码没有区别,除了检查。
    【解决方案4】:

    字符串 sUserName=""; 字符串 sPassword=""; 您将这两个变量都初始化为没有值,我认为您的 SendMail(sUserName,sPassword);正在使用这些变量值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-23
      • 2013-12-18
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2012-07-25
      • 2017-07-05
      相关资源
      最近更新 更多