-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForgotPassword.aspx.cs
63 lines (55 loc) · 2.26 KB
/
ForgotPassword.aspx.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MailKit.Net.Smtp;
using MailKit;
using MimeKit;
public partial class ForgotPassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] != null)
{
Server.Transfer("ShopBook.aspx");
}
}
protected void btnReset_Click(object sender, EventArgs e)
{
List<User> users = (List<User>)Application["users"];
foreach (User u in users)
{
if (tbxEmail.Text == u.Email)
{
Session["rPass"] = u;
int num = new Random().Next(9999999, 999999999);
string nPass = num.ToString();
//update password in Db
u.Password = nPass;
//i am using mailkit instaed of SmtpClient because it is officially replaced in place of smtpClient by microsoft
string EmailMsg = "Hello " + u.Username + " Your Password Has Changed Sucessfully. Since this is the auto Generated Password We Recommand U to Change a new password After u Log In. Your New Generated Password Is " + nPass;
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Book Sore", "noreply.BookStore@mail.com"));
message.To.Add(new MailboxAddress(u.Username, u.Email));
message.Subject = "Password Resetted";
message.Body = new TextPart("plain")
{
Text = EmailMsg
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 465, true);//smtp connect
client.Authenticate("kyawfamily10100@gmail.com", "Kk63996399");//email login
client.Send(message);
client.Disconnect(true);
Response.Write("<script>alert('Passsword Sucessfully Resetted. Please Check Your Mail!');</script>");
Server.Transfer("LoginForm.aspx");
}
}
pnlLoginError.Visible = true;
lblOutput.Text = "invalid Email!";
}
}
}