-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgotpassword.aspx
66 lines (61 loc) · 2.19 KB
/
forgotpassword.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Net.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Database.ConnectionString);
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select pwd from users where email = @email", con);
cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = txtEmail.Text;
Object pwd = cmd.ExecuteScalar();
if ( pwd == null ) {
lblMsg.Text = "Sorry! Invalid Email Account";
return;
}
// send mail
MailMessage msg = new MailMessage();
msg.To.Add( new MailAddress(txtEmail.Text));
msg.From = new MailAddress("[email protected]");
msg.Subject = "Password Recovery";
msg.IsBodyHtml = true;
msg.Body = "Dear User, <p/>Use following password to login.<p/>Password : " + pwd.ToString() + "<p/>Webmaster<br/>yourblogs.com";
SmtpClient server = new SmtpClient("localhost");
server.Send(msg);
lblMsg.Text = "Your password is sent to your email. Use it to login!<p><a href=login.aspx>Login</a>";
}
catch (Exception ex)
{
lblMsg.Text = ex.Message;
}
finally
{
con.Close();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Password Recovery</h2>
<p>
Enter your email address :
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></p>
<p>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
</p>
<p>
<asp:Label ID="lblMsg" runat="server"></asp:Label> </p>
</div>
</form>
</body>
</html>