-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlacesToGo.master.cs
More file actions
170 lines (164 loc) · 6.26 KB
/
PlacesToGo.master.cs
File metadata and controls
170 lines (164 loc) · 6.26 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
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class PlacesToGo : System.Web.UI.MasterPage
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PTGcnn"].ConnectionString);
public static string uimage = "";
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Session["UserId"] != null && HttpContext.Current.Session["UserName"] != null)
{
string UserId = Session["UserId"].ToString();
string UserName = Session["UserName"].ToString();
con.Open();
SqlCommand cmdimg = new SqlCommand("select uimage from UserTable where uid = '" + Session["UserId"] + "'", con);
uimage = "<img src='assets/Images/User/" + cmdimg.ExecuteScalar().ToString() + "' class='avater-img' style=''>";
con.Close();
BindListView();
logoutdiv.Visible = false;
logoutdiv2.Visible = false;
}
else
{
logindiv.Visible = false;
logindiv2.Visible = false;
}
BindListView();
}
public void BindListView()
{
con.Open();
using (SqlDataAdapter sda = new SqlDataAdapter("select top 7 id, categoryName from MainCategory", con))
{
DataTable dt = new DataTable();
sda.Fill(dt);
lv_submenu.DataSource = dt;
lv_submenu.DataBind();
lv_submenu2.DataSource = dt;
lv_submenu2.DataBind();
}
int GetcurrentYear = DateTime.Now.Year;
currentYear.InnerHtml = GetcurrentYear.ToString();
con.Close();
}
protected void BtnLogIn_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtusername.Text) || !string.IsNullOrEmpty(txtpassword.Text))
{
string salt = "";
con.Open();
SqlCommand cmd = new SqlCommand("SELECT usalt FROM UserTable WHERE uname = '" + txtusername.Text + "' or uemail = '" + txtusername.Text + "'", con);
salt = cmd.ExecuteScalar().ToString();
string hashedPassword = HashPassword(txtpassword.Text, salt);
SqlCommand command = new SqlCommand("SELECT uid ,uname FROM UserTable WHERE uname = '" + txtusername.Text + "' or uemail = '" + txtusername.Text + "' AND upassword = '" + hashedPassword + "'", con);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
Session["UserId"] = reader[0].ToString();
Session["Username"] = reader[1].ToString();
string returnUrl = Request.QueryString["returnUrl"];
if (!string.IsNullOrEmpty(returnUrl))
{
Response.Redirect(returnUrl);
}
else
{
Response.Redirect("index.aspx");
}
}
else
{
lblmsg.Visible = true;
lblmsg.Text = "Invalid username or password.";
}
}
else
{
lblmsg.Visible = true;
lblmsg.Text = "please enter valid credentials !";
}
}
private string HashPassword(string password, string salt)
{
string combinedString = string.Concat(password, salt);
byte[] saltedBytes = Encoding.UTF8.GetBytes(combinedString);
SHA256 sha256 = SHA256.Create();
byte[] hashedBytes = sha256.ComputeHash(saltedBytes);
return Convert.ToBase64String(hashedBytes);
}
protected void BtnSendOTP_Click(object sender, EventArgs e)
{
string emailOtp = "";
con.Open();
SqlCommand command = new SqlCommand("SELECT uid,uname,uemail FROM UserTable WHERE uemail = '" + txtEmailOTP.Text + "'", con);
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
emailOtp = reader[2].ToString();
if (!string.IsNullOrEmpty(txtEmailOTP.Text) && !string.IsNullOrEmpty(emailOtp))
{
string otp = GenerateOTP();
Session["OTP"] = otp;
string email = txtEmailOTP.Text;
SendOTP(email, otp);
lblSendOTP.Visible = true;
lblSendOTP.Text = "OTP has been sent to your email.";
}
}
else
{
lblSendOTP.Visible = true;
lblSendOTP.Text = "This email doesn't found / registered.";
}
con.Close();
}
private string GenerateOTP()
{
Random random = new Random();
return random.Next(100000, 999999).ToString();
}
private void SendOTP(string email, string otp)
{
string changepwdURL = "http://placestogoto.com/forgot-password.aspx";
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("omopyt2020@gmail.com");
mailMessage.To.Add(email);
mailMessage.Subject = "Places To Go";
mailMessage.Body = "Your OTP for password reset is: " + otp + "\nClick on the link to change password: " + changepwdURL;
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = "smtp.gmail.com";
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.Credentials = new NetworkCredential("omopyt2020@gmail.com", "jjkhsulyfsbgdvks");
smtpClient.Send(mailMessage);
lblSendOTP.Visible = true;
lblSendOTP.Text = "OTP has been sent to your email.";
}
protected void AddBlog_Click(object sender, EventArgs e)
{
if (HttpContext.Current.Session["UserId"] != null && HttpContext.Current.Session["UserName"] != null)
{
Response.Redirect("add-blogs.aspx");
}
else
{
string returnUrl = HttpUtility.UrlEncode(Request.Url.PathAndQuery);
Response.Redirect("login.aspx?returnUrl=" + returnUrl);
}
}
protected void btnDashboard_Click(object sender, EventArgs e)
{
Response.Redirect("dashboard.aspx");
}
}