TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sk Jha
NA
113
43.4k
How send password to authenticate user
Dec 22 2017 11:39 PM
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."
;
}
}
Reply
Answers (
1
)
Asp.Net master page with script manager and update panel
how to auto filled txtbox when i click on send button in as