email password from sql database

Reply

Join Date: Sep 2008
Posts: 351
Reputation: freshfitz is an unknown quantity at this point 
Solved Threads: 30
freshfitz freshfitz is offline Offline
Posting Whiz

email password from sql database

 
0
  #1
Feb 7th, 2009
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

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: email password from sql database

 
0
  #2
Feb 9th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 351
Reputation: freshfitz is an unknown quantity at this point 
Solved Threads: 30
freshfitz freshfitz is offline Offline
Posting Whiz

Re: email password from sql database

 
0
  #3
Feb 9th, 2009
I ended up getting it I had to use this
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;
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: email password from sql database

 
0
  #4
Feb 9th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 953 | Replies: 3
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC