ASP.NET - Forgot Password Template - Asked By msakt on 04-Apr-12 01:15 AM

any body send Forgot Password Template in using c#
Chintan Vaghela replied to msakt on 04-Apr-12 01:25 AM


Need to create on email textbox and one button for send mail. If email address exist in user table then associate user password send to this email address. Other wise display message

Make as following way



EMAIL Adderss :<asp:TextBox ID="Textemail" runat="server"></asp:TextBox>

    <asp:Button ID="btnSend" runat="server" Text="Password Send to Mail" OnClick="btnSubmit_Click" />



  protected void btnSubmit_Click(object sender, EventArgs e)



      // Select * from UserTable where email= Textemail.text


      // IF recored found then Send Mail

      // Other wise Display message your email adderess is incorrect



Hope this helpful!


Suchit shah replied to msakt on 04-Apr-12 02:16 AM
the forgot password webpage you can use the password recovery control which is available in control that you can do it by using the membership concept... the nice example of it given here :
and on one other way I have used stored procedures to retrieve my username and password through mailid .
Here my textbox name is emailid.text

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
//using System.Web.Mail;
using System.Net.Mime;
using System.Net.Configuration;
namespace Project
public partial class ForgotPassword : Form
public ForgotPassword()
SqlConnection con;
string strbody;
private void button1_Click(object sender, EventArgs e)
con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
//SqlConnection con = new SqlConnection (@"integrated security=yes;initial catalog=vinay;database=.\sqlexpress");
//MessageBox.Show("Database Connected");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "FPassword";//Fpassword is my stored procedure
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1, p2, p3,p4,p5;
p1 = cmd.Parameters.Add("@emailid", SqlDbType.VarChar, 30);
p1.Direction = ParameterDirection.Input;
p1.Value = emailid.Text;
p2 = cmd.Parameters.Add("@uname", SqlDbType.Int);
p2.Direction = ParameterDirection.Output;

p3 = cmd.Parameters.Add("@pwd", SqlDbType.Int);
p3.Direction = ParameterDirection.Output;
p4 = cmd.Parameters.Add("@count", SqlDbType.VarChar, 30);
p4.Direction = ParameterDirection.Output;
p5 = cmd.Parameters.Add("@user", SqlDbType.VarChar, 30);
p5.Direction = ParameterDirection.Output;
SqlDataAdapter da = new SqlDataAdapter("select * from LoginCheck where EmailId= '" + emailid.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds, "Pass");

int x = int.Parse(cmd.Parameters["@count"].Value.ToString());
//string user = cmd.Parameters["@user"].Value.ToString();
//string strusername = emailid.Text;
if (x == 1)

strbody = strbody + "Thanks," + Environment.NewLine;
strbody = strbody + "Username : "+ds.Tables[0].Rows[0]["username"].ToString()+Environment.NewLine;
strbody = strbody + "Password : "+ds.Tables[0].Rows[0]["pasword"].ToString() + Environment.NewLine;
strbody = strbody + Environment.NewLine;
strbody = strbody + "Administrator," + Environment.NewLine;
MailAddress fromaddress = new MailAddress(emailid.Text);//Here my textbox name is emailid.text
System.Web.Mail.MailMessage mail = new System.Web.Mail.MailMessage();
//SmtpClient SmtpMail = new SmtpClient();
mail.To = emailid.Text;
mail.From = "";
mail.Subject = "Reg:Password";
mail.Body = strbody;
System.Web.Mail.SmtpMail.SmtpServer = "";//use ur SmtpServer Number.
// System.Net.Mail.SmtpClient=
MessageBox.Show("Username and Password has been sent to ur Mail ID");

//label4.Visible = true;// error message (invalid userid or password)
MessageBox.Show("Invalid EmailID");
Stored Procedure for Fpassword
//Here LoginCheck is my tablename.
alter procedure FPassword(@uname varchar(20) output,@pwd varchar(20) output,@emailid varchar(50) ,@count varchar(20) output,@user varchar(20)output)
select username,pasword from logincheck where
select @count= count(*) from LoginCheck where
select @user= username from LoginCheck where and
dipa ahuja replied to msakt on 04-Apr-12 03:38 AM
If you are using custome password recovery the just have to send the mail to the user that your password is:

protected void btnSent_Click(object sender, EventArgs e)
  string toEmailAddress = "";
  string GmailId = "";
  string password = "xxx";
  SqlDataAdapter da = new SqlDataAdapter("Select uname,password from user where username='" + TextBox1.Text
  + "'", "ConnectionSTring");
  DataTable dt = new DataTable();
  string bodyMsg = "Your Username :" + dt.Rows[0]["uname"] + "and passowrd:" + dt.Rows[0]["password"].ToString();
  MailMessage mail = new MailMessage();
  mail.From = new MailAddress(GmailId);
  mail.Subject = txtSubject.Text;
  mail.Body = bodyMsg;
  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient("");
  smtp.EnableSsl = true;
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);