Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
1
Reply
How send password to authenticate user
Sk Jha
Dec 22 2017 11:39 PM
139
Reply
How to make forget password where i want to recover password by email.
here is my code but its not working.
Connection c =
new
Connection();
protected
void
btnPassword_Click(
object
sender, EventArgs e)
{
string
userId =
""
;
string
email =
""
;
string
password =
""
;
using
(SqlConnection con =
new
SqlConnection(c.GetConnectionString()))
{
using
(SqlCommand cmd =
new
SqlCommand(
"SELECT * FROM User_login WHERE userId = @user"
))
{
cmd.Parameters.AddWithValue(
"@user"
, txtUser.Text.Trim());
cmd.Connection = con;
con.Open();
using
(SqlDataReader dr = cmd.ExecuteReader())
{
if
(dr.Read())
{
userId = dr[
"userId"
].ToString();
email = dr[
"email"
].ToString();
password = dr[
"Password"
].ToString();
}
}
con.Close();
}
}
if
(!
string
.IsNullOrEmpty(password))
{
MailMessage mm =
new
MailMessage(
"
[email protected]
"
,email);
mm.Subject =
"Password Recovery"
;
mm.Body =
string
.Format(
"Hi {0},<br /><br />Your password is {1}.<br /><br />Thank You."
, userId, password);
mm.IsBodyHtml =
true
;
SmtpClient smtp =
new
SmtpClient();
smtp.Host =
"smtp.gmail.com"
;
smtp.EnableSsl =
true
;
NetworkCredential NetworkCred =
new
NetworkCredential();
NetworkCred.UserName =
"
[email protected]
"
;
NetworkCred.Password =
"*****"
;
smtp.UseDefaultCredentials =
true
;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
er.Visible =
true
;
ltrError.Text =
"Password has been sent to your email address."
;
}
else
{
er.Visible =
true
;
ltrError.Text =
"This email address does not match our records."
;
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Asp.Net master page with script manager and update panel
how to auto filled txtbox when i click on send button in as