943,699 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1341
  • ASP.NET RSS
Feb 7th, 2009
0

email password from sql database

Expand Post »
I can't figure out how to email the password from a sql database I have a formview on my webpage can I pull it from there? or can I pull it directly on my backend code? Using C# I tried + passwordlabel + I tried using findcontrol.formview I can seem to get it right

The part where I have label2.text = findcontrol... I get this in the email System.Web.UI.WebControls.Label

my email.aspx code

ASP.NET Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Net.Mail;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Web.Configuration;
  12. using System.Net;
  13. using System.Text;
  14. using System.IO;
  15. using System.Data.SqlClient;
  16.  
  17.  
  18. public partial class Forgot : System.Web.UI.Page
  19. {
  20. protected void Page_Load(object sender, EventArgs e)
  21. {
  22.  
  23. }
  24. protected void bc_fpwd_submit_button_Click(object sender, EventArgs e)
  25. {
  26. {
  27. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString.ToString());
  28. con.Open();
  29. SqlCommand sqlCMD = con.CreateCommand();
  30. sqlCMD.CommandText = "SELECT * FROM users WHERE email = @email"; // (this should really be a stored procedure, shown here for simplicity)
  31.  
  32. // Fill our parameters
  33.  
  34. sqlCMD.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = bc_fpwd_uid_textbox.Text;
  35.  
  36. SqlDataAdapter sqlAD = new SqlDataAdapter(sqlCMD);
  37. DataSet dsDataSet = new DataSet();
  38. sqlAD.Fill(dsDataSet);
  39. if (dsDataSet.Tables[0].Rows.Count > 0)
  40. {
  41. Form.Visible = false;
  42. FoundPW.Visible = true;
  43. Label1.Text = bc_fpwd_uid_textbox.Text;
  44. bc_fuid_validator.Visible = true;
  45.  
  46. Label2.Text = this.FormView1.FindControl("passwordLabel").ToString();
  47. string MyValue = Label2.Text;
  48.  
  49.  
  50. // Do this if username not found in database
  51. }
  52. else
  53. {
  54. Form.Visible = true;
  55. FoundPW.Visible = false;
  56. bc_no_uid_label.Visible = true;
  57. }
  58. con.Close();
  59. sqlAD.Dispose();
  60. }
  61.  
  62. }
  63.  
  64.  
  65.  
  66. protected void bc_fpwd_cancel_button_Click(object sender, EventArgs e)
  67. {
  68.  
  69. }
  70. protected void Button1_Click(object sender, EventArgs e)
  71. {
  72. if (Page.IsValid)
  73. {
  74. System.Configuration.Configuration config
  75. = WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath);
  76. AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings");
  77.  
  78. //appSettings.Settings["EmailHost"].Value
  79. string emailHost = appSettings.Settings["EmailHost"].Value;
  80. string fromAddress = appSettings.Settings["FromEmailAddr"].Value;
  81. string toAddress = "me@vortexamerica.com";
  82.  
  83.  
  84.  
  85. SmtpClient smtpClient = new SmtpClient(emailHost);
  86.  
  87. // Default in IIS will be localhost
  88. //smtpClient.Host = "localhost";
  89.  
  90. //Default port will be 25
  91. smtpClient.Port = 25;
  92.  
  93.  
  94. MailMessage message = new MailMessage();
  95. message.IsBodyHtml = false;
  96. message.Priority = MailPriority.High;
  97. message.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
  98.  
  99. try
  100. {
  101. message.Subject = "Paal Camera Forgot Password";
  102. message.Body += "Sender: " + bc_fpwd_uid_textbox.Text + "\n";
  103. message.Body += "Password: " + FormView1.FindControl("passwordlabel").ToString()+ "\n";
  104.  
  105.  
  106.  
  107. smtpClient.Send(fromAddress, toAddress, message.Subject, message.Body);
  108.  
  109.  
  110. }
  111. catch (Exception ex)
  112. {
  113. // Display error panel
  114.  
  115.  
  116. // Log error
  117.  
  118. }
  119.  
  120. }
  121.  
  122. }
  123.  
  124. }
Last edited by freshfitz; Feb 7th, 2009 at 5:10 pm.
Similar Threads
Reputation Points: 12
Solved Threads: 36
Posting Pro in Training
freshfitz is offline Offline
436 posts
since Sep 2008
Feb 9th, 2009
0

Re: email password from sql database

Try this

Label2.Text = (Label) this.FormView1.FindControl("passwordLabel").Text;
Last edited by peter_budo; Feb 15th, 2009 at 7:53 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 16
Solved Threads: 18
Junior Poster
Aneesh_Argent is offline Offline
104 posts
since Dec 2008
Feb 9th, 2009
0

Re: email password from sql database

I ended up getting it I had to use this
Quote ...
using web = System.Web.UI.WebControls;

web.Label password = (web.Label)FormView1.FindControl("passwordlabel");
string mypassword = password.Text;

//Label2.Text = this.FormView1.FindControl("passwordLabel").ToString();
Label2.Text = password.Text;
Reputation Points: 12
Solved Threads: 36
Posting Pro in Training
freshfitz is offline Offline
436 posts
since Sep 2008
Feb 9th, 2009
0

Re: email password from sql database

The fact that passwords are recoverable in clear text from your database should be regarded as a serious (or fatal) security flaw.

Ideally, you should only be storing a cryptographically secure hash of the password.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: WHERE clause in vwd 2005 express
Next Thread in ASP.NET Forum Timeline: asp.net with flash page speed optimization





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC