Forgot password how to retrieve using email address in Asp.Net C#

ForGot password How to retrieve password using Email in Asp.Net With Sql Server Database

Introduction :  
This Artical Explain How to Retrieve forgot password using email address in asp.net 3-Tier Architecture using the SQL  Server Database 

Step 1: Create database  as following

CREATE TABLE [dbo].[user_master] (
    [Id]       INT           IDENTITY (1, 1) NOT NULL,
    [name]     NVARCHAR (50) NOT NULL,
    [password] NVARCHAR (50) NOT NULL,
    [email]    NVARCHAR (50) NOT NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC)
);

Step 2:  Create  Data access class and give name DAL.cs

 public class DAL
    {
        public int id { get; set; }
        public string name { get; set; }
        public string password { get; set; }
        public string  email { get; set; }
    }

Step 3 :Create Business Access Layer and give name BAL.cs

 public class BAL
  {
  SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:
  \3_tier_ForgotPassword\3_tier_ForgotPassword\App_Data\Db1.mdf;Integrated Security=True"
);


  public DataTable Forgotpwd(DAL da)
  {
  con.Open();
  DataTable dt = new DataTable();

  SqlDataAdapter adp = new SqlDataAdapter("Select name,password from user_master where
  email
= '" + da.email + "'", con);
          
  adp.Fill(dt);
  con.Close();
  return dt;
   }
Step 4 : In WebForm

 Step 5:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Net.Mail;
using System.Net;
namespace _3_tier_ForgotPassword
{
  public partial class forgotpassword : System.Web.UI.Page
  {
   BAL ba = new BAL();
   DAL da = new DAL();
   DataTable dt = new DataTable();
   DataSet ds = new DataSet()
   protected void Page_Load(object sender, EventArgs e)
   {

   }

  protected void Button1_Click(object sender, EventArgs e)
  {

   da.email =txt_mail.Text;
   dt = ba.Forgotpwd(da);
   if (dt.Rows.Count > 0)
   {
    MailMessage email = new MailMessage();
    email.From = new MailAddress(txt_mail.Text);
    email.To.Add(txt_mail.Text);
    email.Subject = "Your Forgot Password:";
    email.Body = "Hi,Your Username is: " + ds.Tables[0].Rows[0]["name"] + "
    Your Password is: " + ds.Tables[0].Rows[0]["password"] + " ";
    email.IsBodyHtml = true;
    SmtpClient smtpc = new SmtpClient();
    smtpc.Port = 587;
    smtpc.UseDefaultCredentials = false;
    smtpc.EnableSsl = true;
    Label1.Text = "xyz123@gmail.com";
    Label2.Text = "1234567890";
    smtpc.Credentials = new NetworkCredential(Label1.Text, Label2.Text);
    smtpc.Send(email);
    Label1.Text = "Your password has been sent to your email address";

   }
   else
    {
     Label2.Text = "This email address is not exist in our Database try again";
     }
   }
}

 
 
Previous
Next Post »

1 comments:

Write comments
Sarah
AUTHOR
26 July 2016 at 10:30 delete

There was a time when it was hard to meet our family and friends for long time. But today is the time when you can get in touch with every single friend and family member.
https://drive.google.com/open?id=0B0kZrnZTkuR_eENFSlh6NlRpcUE

Reply
avatar