-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResetPassword.aspx.cs
More file actions
176 lines (168 loc) · 9.06 KB
/
ResetPassword.aspx.cs
File metadata and controls
176 lines (168 loc) · 9.06 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Security.Cryptography;
public partial class ResetPassword : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["reg"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
string reset_otp = Request.QueryString["reset_otp"];
string emailurl = Request.QueryString["Email"];
con.Open();
string str = "Select reset_otp,email from [signup] where reset_otp!='' and reset_otp='" + reset_otp + "' and Email ='" + Base64Decode(emailurl) + "'";
SqlCommand activateAct = new SqlCommand(str, con);
SqlDataReader read = activateAct.ExecuteReader();
if (!read.HasRows)
{
Label4.Text = "Reset Password link is expired.";
Label4.ForeColor = System.Drawing.Color.Red;
ResetPwdPH.Visible = false;
}
con.Close();
}
protected void ResetPWDButton_Click(object sender, EventArgs e)
{
string reset_otp = Request.QueryString["reset_otp"];
string emailurl = Request.QueryString["Email"];
con.Open();
string abhijeet = "Select reset_otp,email from [signup] where reset_otp!='' and reset_otp='" + reset_otp + "' and Email ='" + Base64Decode(emailurl) + "'";
SqlCommand activateAct = new SqlCommand(abhijeet, con);
SqlDataReader read = activateAct.ExecuteReader();
if (read.HasRows)
{
con.Close();
con.Open();
string updateAct = "update [signup] set reset_otp='',Password=@Password where Email ='" + Base64Decode(emailurl) + "'";
SqlCommand usrActivate = new SqlCommand(updateAct, con);
usrActivate.Parameters.AddWithValue("@Password", MyEncrypt(t1.Text));
usrActivate.ExecuteNonQuery();
con.Close();
try
{
MailMessage mail = new MailMessage();
mail.To.Add(Base64Decode(emailurl).ToString());
mail.From = new MailAddress("studenttraining@technsl.in");
mail.Subject = "Your password Successfully. Thankyou.";
string emailBody = "";
emailBody += "<div style='background:#FFFFFF; font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px; margin:0; padding:0;'>";
emailBody += "<table cellspacing='0' cellpadding='0' border='0' width='100%' style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;'>";
emailBody += "<tbody>";
emailBody += "<tr>";
emailBody += "<td valign='top' style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;'>";
emailBody += "<div style='width:600px;margin-left:auto;margin-right:auto;clear:both;'>";
emailBody += "<div style='float:left;width:600px;min-height:35px;font-size:26px;font-weight:bold;text-align:left'>";
emailBody += "<div style='clear:both;width:100%;text-align:center;'> Website</div>";
emailBody += "<div style='clear:both;width:100%;text-align:center;font-size:11px;font-style:italic;'> website World!</div>";
emailBody += "</div>";
emailBody += "</div>";
emailBody += "</td>";
emailBody += "</tr>";
emailBody += "</tbody>";
emailBody += "</table>";
emailBody += "<table cellspacing='0' cellpadding='0' border='0' width='600' style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;margin-left:auto;margin-right:auto;'>";
emailBody += "<tbody>";
emailBody += "<tr>";
emailBody += "<td valign='top' colspan='2' style='width:600px;padding-left:20px;padding-right:20px;font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;'>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;padding-top:15px;line-height:22px;margin:0px;font-weight:bold;padding-bottom:5px'>Hi User,</p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;color:rgb(41,41,41)'>Your Password is reset Successfully.</p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;color:rgb(41,41,41)'>Your New Password is <b>" + t1.Text.ToString() + "</b></p>";
emailBody += "<p> </p><p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;margin:0px'>If you have any additional queries, please feel free to reach out us at +91 XXXXX XXXXX or drop us an email at <a href='mailto:Websiteweb.com' style='text-decoration:none;font-style:normal;font-variant:normal;font-weight:normal;font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:normal;color:rgb(162,49,35)' target='_blank'>example@domain.com</a>. We are here to help you.</p>";
emailBody += "<p> </p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;line-height:22px;margin:0px;font-weight:bold'>Best Regards,</p>";
emailBody += "<p style='font-family:Arial,Helvetica,Verdana,sans-serif; font-size:14px;color:rgb(41,41,41);line-height:22px;margin:0px'>WebsiteSupport</p>";
emailBody += "</td>";
emailBody += "</tr>";
emailBody += "</tbody>";
emailBody += "</table>";
emailBody += "</div>";
mail.Body = emailBody;
mail.IsBodyHtml = true;
/*
SmtpClient smtp = new SmtpClient();
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential("computercomrade37@gmail.com", "mk62955@gmail");
smtp.Send(mail);
*/
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.technsl.in";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential("studenttraining@technsl.in", "TechNsl123@");
smtp.Send(mail);
}
catch (Exception ex)
{
throw ex;
// msg = ex.Message;
}
Label4.Text = "Your password is reset successfully.";
Label4.ForeColor = System.Drawing.Color.Red;
//Response.Redirect("login.aspx");
}
else
{
Label4.Text = "Reset Password link is expired.";
Label4.ForeColor = System.Drawing.Color.Red;
}
}
private string MyEncrypt(string returnText)
{
string EncryptionKey = "E5C2B81A3B2B2";
byte[] clearBytes = Encoding.Unicode.GetBytes(returnText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
returnText = Convert.ToBase64String(ms.ToArray());
}
}
return returnText;
}
private string MyDecrypt(string returnText)
{
string EncryptionKey = "E5C2B81A3B2B2";
byte[] cipherBytes = Convert.FromBase64String(returnText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(cipherBytes, 0, cipherBytes.Length);
cs.Close();
}
returnText = Encoding.Unicode.GetString(ms.ToArray());
}
}
return returnText;
}
public static string Base64Decode(string base64EncodedData)
{
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);
}
}