Advertisement
Guest User

Untitled

a guest
Sep 11th, 2017
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. //string username = Request.Form["UserName"];
  2. string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:inetpubwwwrootmyfoldermydatabase";
  3. using (OleDbConnection con = new OleDbConnection(str))
  4. using (OleDbCommand cmd = con.CreateCommand())
  5. {
  6. cmd.CommandText = "SELECT password, email FROM [users] WHERE username = ?";
  7. cmd.Parameters.Add("user", OleDbType.VarChar).Value = Request.Form["UserName"];
  8. con.Open();
  9.  
  10. using (OleDbDataReader reader = cmd.ExecuteReader())
  11. {
  12. while (reader.Read())
  13. {
  14. string password = reader["password"].ToString();
  15. string accountemail = reader["email"].ToString();
  16.  
  17. string from = "office email"; //send from admin/mail server
  18. string to = "accountemail"; //send to respective user
  19. string subject = "forgot password";
  20. string body = "This is the password that you have requested: " + password + ". Please do not reply, this is an automated email."; //content of the email
  21. try
  22. {
  23. var fromAddress = new MailAddress(from);
  24. MailMessage mail = new MailMessage();
  25. SmtpClient smtp = new SmtpClient();
  26.  
  27. MailAddressCollection m = new MailAddressCollection();
  28. m.Add(to);
  29. mail.Subject = subject;
  30. mail.From = new MailAddress(from);
  31. mail.Body = body;
  32. mail.IsBodyHtml = true;
  33. mail.ReplyToList.Add(fromAddress);
  34. mail.To.Add(m[0]);
  35. smtp.Host = "smtp.gmail.com";
  36. smtp.Port = 587;
  37. smtp.EnableSsl = true;
  38. smtp.Credentials = new System.Net.NetworkCredential(from, "mypassword");
  39. ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
  40.  
  41. smtp.Send(mail);
  42.  
  43. MessageBox.Show("Success, your password has been sent to you.");
  44. }
  45. catch (Exception ex)
  46. {
  47. Response.Write(ex.Message);
  48. Response.Redirect("Login.aspx", false);
  49. }
  50. finally
  51. {
  52. con.Close();
  53. }
  54. }
  55. }
  56. }
  57.  
  58. cmd.CommandText = "SELECT password, email FROM [users] WHERE username = @user";
  59. cmd.Parameters.Add("@user", OleDbType.VarChar).Value = Request.Form["UserName"];
  60.  
  61. string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:inetpubwwwrootmyfoldermydatabase";
  62. string password = "";
  63. string accountemail="";
  64. using (OleDbConnection con = new OleDbConnection(str))
  65. {
  66. using (OleDbCommand cmd = con.CreateCommand())
  67. {
  68. cmd.CommandText = "SELECT password, email FROM [users] WHERE username = @user";
  69. cmd.Parameters.Add("@user", OleDbType.VarChar).Value = Request.Form["UserName"];
  70. con.Open();
  71.  
  72. using (OleDbDataReader reader = cmd.ExecuteReader())
  73. {
  74. while (reader.Read())
  75. {
  76. password = reader["password"].ToString();
  77. accountemail = reader["email"].ToString();
  78.  
  79. }
  80. }
  81. }
  82. }
  83. string fromaddress = "office email"; //send from admin/mail server
  84. string toaddress = accountemail; //send to respective user
  85. string subject = "forgot password";
  86. string body = String.Concat("This is the password that you have requested: " ,password, ". Please do not reply, this is an automated email."); //content of the email
  87. try
  88. {
  89. var fromAddress = new MailAddress(fromaddress);
  90. MailMessage mail = new MailMessage();
  91. SmtpClient smtp = new SmtpClient();
  92.  
  93. MailAddressCollection m = new MailAddressCollection();
  94. m.Add(toaddress);
  95. mail.Subject = subject;
  96. mail.From = new MailAddress(fromaddress);
  97. mail.Body = body;
  98. mail.IsBodyHtml = true;
  99. mail.ReplyToList.Add(fromAddress);
  100. mail.To.Add(m[0]);
  101. smtp.Host = "smtp.gmail.com";
  102. smtp.Port = 587;
  103. smtp.EnableSsl = true;
  104. smtp.Credentials = new System.Net.NetworkCredential(from, "mypassword");
  105. ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
  106.  
  107. smtp.Send(mail);
  108.  
  109. MessageBox.Show("Success, your password has been sent to you.");
  110. }
  111. catch (Exception ex)
  112. {
  113. Response.Write(ex.Message);
  114. Response.Redirect("Login.aspx", false);
  115. }
  116.  
  117. cmd.Parameters.Add(Request.Form["UserName"]);
  118.  
  119. string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:inetpubwwwrootmyfoldermydatabase";
  120. using (OleDbConnection con = new OleDbConnection(str))
  121. using (OleDbCommand cmd = con.CreateCommand())
  122. {
  123. cmd.CommandText = "SELECT [password], [email] FROM [users] WHERE username = ?";
  124. cmd.Parameters.Add("user", OleDbType.VarChar).Value = Request.Form["UserName"];
  125. con.Open();
  126.  
  127. using (OleDbDataReader reader = cmd.ExecuteReader())
  128. {
  129. while (reader.Read())
  130. {
  131. string password = reader["password"].ToString();
  132. string accountemail = reader["email"].ToString();
  133.  
  134. string from = "office email"; //send from admin/mail server
  135. string to = "accountemail"; //send to respective user
  136. string subject = "forgot password";
  137. string body = "This is the password that you have requested: " + password + ". Please do not reply, this is an automated email."; //content of the email
  138. try
  139. {
  140. var fromAddress = new MailAddress(from);
  141. MailMessage mail = new MailMessage();
  142. SmtpClient smtp = new SmtpClient();
  143.  
  144. MailAddressCollection m = new MailAddressCollection();
  145. m.Add(to);
  146. mail.Subject = subject;
  147. mail.From = new MailAddress(from);
  148. mail.Body = body;
  149. mail.IsBodyHtml = true;
  150. mail.ReplyToList.Add(fromAddress);
  151. mail.To.Add(m[0]);
  152. smtp.Host = "smtp.gmail.com";
  153. smtp.Port = 587;
  154. smtp.EnableSsl = true;
  155. smtp.Credentials = new System.Net.NetworkCredential(from, "mypassword");
  156. ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
  157.  
  158. smtp.Send(mail);
  159.  
  160. MessageBox.Show("Success, your password has been sent to you.");
  161. }
  162. catch (Exception ex)
  163. {
  164. Response.Write(ex.Message);
  165. Response.Redirect("Login.aspx", false);
  166. }
  167. finally
  168. {
  169. con.Close();
  170. }
  171. }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement