locked
im not getting my forgot password RRS feed

  • Question

  • User849610253 posted

    Hi,

    im writng this code for retrieve the password which i was forgot ... but still im not getting anything ... please tell me where the error ..

    protected void forgot_Click(object sender, EventArgs e)
    {
    MySqlConnection con = new MySqlConnection("Server=localhost;Port=3306;Database=realestate_internal;Uid=mysql;Pwd="****;");
    con.Open();
    MySqlCommand cmd = new MySqlCommand("SELECT User_Name,User_Password FROM user Where User_Email='" + txtUserName.Text + "'", con);
    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);
    con.Close();
    if (ds.Tables[0].Rows.Count > 0)
    {
    MailMessage email = new MailMessage();
    email.From = new MailAddress("praveen.l@gmail.com");
    email.To.Add(txtUserName.Text);
    email.Subject = "Your forgot password:";
    email.Body = "Hi,<br/> Your username is:" + ds.Tables[0].Rows[0]["User_Name"] + "<br/><br/> Your Password is:" + ds.Tables[0].Rows[0]["User_Password"] + "<br/>";
    email.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.Credentials = new System.Net.NetworkCredential("praveen.l@gmail.com", "*****");
    smtp.EnableSsl = true;
    smtp.Send(email);
    lbltext.InnerText = "Your Password Details Sent to your mail";
    txtUserName.Text = "";

    }
    else
    {
    lbltext.InnerText = "The Email you entered not exists.";
    }
    //catch(Exception ex)
    //{
    // Console.WriteLine("{0} Exception caught.", ex);
    //}
    }

    Thursday, September 18, 2014 9:06 AM

All replies

  • User-1806150748 posted

    Can you run same query in MySQL console and verify result. As a side note try this  txtUserName.Text.Trim(), may be some whitespace is causing the problem,.

    Thursday, September 18, 2014 10:23 AM
  • User849610253 posted

    Hi arindamnayak,

    i tried wat u said but it doesn't resolve my problem ... and i use this code now then also it wont come please help guys......

    protected void forgot_Click(object sender, EventArgs e)
    {
    User user = new DL_Real_Estate_Internal.User();
    //user.Email = txtForgotPassword.Value;
    User ValidUser = new User();
    BL_User_Agent UAgent = new BL_User_Agent();
    ValidUser = UAgent.ForgotPassword(user.Email);

    string mysql="SELECT User_Name,User_Password FROM user Where User_Email='" + txtUserName.Text.Trim() + "'";
    MySqlCommand cmd = new MySqlCommand("mysql",con);
    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);

    if (user != null)
    {
    MailMessage email = new MailMessage();
    email.From = new MailAddress("praveen.l@gmail.com");
    email.To.Add(txtUserName.Text.Trim());
    email.Subject = "Your forgot password:";
    email.Body = "Hi,<br/> Your username is:" + ds.Tables[0].Rows[0]["User_Name"] + "<br/><br/> Your Password is:" + ds.Tables[0].Rows[0]["User_Password"] + "<br/>";//im getting error in this line.... System.IndexOutOfRangeException: Cannot find table 0.
    email.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.Credentials = new System.Net.NetworkCredential("praveen.l@gmail.com", "******");
    smtp.EnableSsl = true;
    smtp.Send(email);
    lbltext.InnerText = "Your Password Details Sent to your mail";
    txtUserName.Text= "";
    }
    else
    {
    this.AlertBoxMessage.InnerHtml = "Email Address does't Exist.";
    this.AlertBox.Visible = true;
    }
    }

    regards,

    Praveen.

    Friday, September 19, 2014 12:51 AM
  • User1428246847 posted

    praveen_527

    ds.Tables[0].Rows[0]["User_Password"] + "<br/>";//im getting error in this line.... System.IndexOutOfRangeException: Cannot find table 0.

    Conclusion:

    string mysql="SELECT User_Name,User_Password FROM user Where User_Email='" + txtUserName.Text.Trim() + "'";
    MySqlCommand cmd = new MySqlCommand("mysql",con);
    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds);

    ds is empty

    So a wild guess is that txtUserName.Text.Trim() returns an empty string. Put a put a breakpoint on that first line and check what is in txtUserName.

    Monday, September 22, 2014 5:40 AM