altaf9909

Forgot password get by mail using SMTP

Feb 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Configuration;
  10. using System.Net.Mail;
  11. using System.Net;
  12.  
  13. public partial class ForgetPassword : System.Web.UI.Page
  14. {
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.  
  18.     }
  19.  
  20.     protected void Button1_Click(object sender, EventArgs e)
  21.     {
  22.         string username = "";
  23.         string password = "";
  24.         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
  25.         SqlCommand cmd = new SqlCommand("select username, password from session_login where username=@username", con);
  26.         cmd.Parameters.AddWithValue("@username", txtemail.Text);
  27.         con.Open();
  28.         using (SqlDataReader sdr = cmd.ExecuteReader())
  29.         {
  30.  
  31.             if (sdr.Read())
  32.             {
  33.                 username = sdr["username"].ToString();
  34.                 password = sdr["password"].ToString();
  35.                 MailMessage mm = new MailMessage("your email", txtemail.Text);
  36.                 mm.Subject = "Just Use For Demo!";
  37.                 mm.Body = string.Format("Hello: Your Password No is <h1>{0}</h1><br/> ", password);
  38.                 mm.IsBodyHtml = true;
  39.                 SmtpClient smtp = new SmtpClient();
  40.                 smtp.Host = "smtp.gmail.com";
  41.                 smtp.EnableSsl = true;
  42.                 NetworkCredential nc = new NetworkCredential();
  43.                 nc.UserName = "your email";
  44.                 nc.Password = "Your password";
  45.                 smtp.UseDefaultCredentials = true;
  46.                 smtp.Credentials = nc;
  47.                 smtp.Port = 25;
  48.                 smtp.Send(mm);          
  49.             }
  50.  
  51.         }
  52.         con.Close();
  53.        
  54.          
  55.  
  56.          
  57.     }
  58.     protected void linkforget(object sender, EventArgs e)
  59.     {
  60.         Response.Redirect("ForgetPassword.aspx");
  61.     }
  62.  
  63. }
Add Comment
Please, Sign In to add comment