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

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

Hello,

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!

Thanks

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 :
https://hyd-outlook.wipro.com/owa/redir.aspx?C=677ddc88a6c848bfb44988814b4aed36&URL=http%3a%2f%2fwww.codeproject.com%2fArticles%2f46369%2fImproved-ASP-NET-Password-Recovery
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()
{
InitializeComponent();
}
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");

con.Open();
cmd.ExecuteNonQuery();
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 = "https://hyd-outlook.wipro.com/owa/redir.aspx?C=677ddc88a6c848bfb44988814b4aed36&URL=mailto%3axxx%40gmail.com";
mail.Subject = "Reg:Password";
mail.Body = strbody;
System.Web.Mail.SmtpMail.SmtpServer = "0.0.0.0";//use ur SmtpServer Number.
// System.Net.Mail.SmtpClient=
System.Web.Mail.SmtpMail.Send(mail);
MessageBox.Show("Username and Password has been sent to ur Mail ID");

}
else
{
//label4.Visible = true;// error message (invalid userid or password)
MessageBox.Show("Invalid EmailID");
con.Close();
}
}
}
}
 
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)
as
begin
select username,pasword from logincheck where https://hyd-outlook.wipro.com/owa/redir.aspx?C=677ddc88a6c848bfb44988814b4aed36&URL=mailto%3aEmailId%3d%40emailid
select @count= count(*) from LoginCheck where https://hyd-outlook.wipro.com/owa/redir.aspx?C=677ddc88a6c848bfb44988814b4aed36&URL=mailto%3aEmailId%3d%40emailid
select @user= username from LoginCheck where https://hyd-outlook.wipro.com/owa/redir.aspx?C=677ddc88a6c848bfb44988814b4aed36&URL=mailto%3ausername%3d%40uname and https://hyd-outlook.wipro.com/owa/redir.aspx?C=677ddc88a6c848bfb44988814b4aed36&URL=mailto%3apasword%3d%40pwd
end
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 = "UserToWhomSendPassword@gmail.com";
  string GmailId = "xxx@gmail.com";
  string password = "xxx";
 
  SqlDataAdapter da = new SqlDataAdapter("Select uname,password from user where username='" + TextBox1.Text
  + "'", "ConnectionSTring");
  DataTable dt = new DataTable();
  da.Fill(dt);
 
 
  string bodyMsg = "Your Username :" + dt.Rows[0]["uname"] + "and passowrd:" + dt.Rows[0]["password"].ToString();
 
 
  MailMessage mail = new MailMessage();
  mail.To.Add(toEmailAddress);
 
  mail.From = new MailAddress(GmailId);
  mail.Subject = txtSubject.Text;
  mail.Body = bodyMsg;
  mail.IsBodyHtml = true;
 
   
  SmtpClient smtp = new SmtpClient("smtp.gmail.com");
  smtp.EnableSsl = true;
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
  smtp.Send(mail);
}