-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auth.cs
219 lines (194 loc) · 6.51 KB
/
Auth.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace PASPAS
{
public partial class Auth : Form
{
readonly SqlConnection conn = new SqlConnection("Data Source=YOURSERVERNAME;Initial Catalog=PASPAS;Persist Security Info=true;User ID=sa;Password=1");
int MoveCP;
int MapX;
int MapY;
public Auth()
{
InitializeComponent();
}
private void ControlPanel_MouseDown(object sender, MouseEventArgs e)
{
MoveCP = 1;
MapX = e.X;
MapY = e.Y;
}
private void ControlPanel_MouseUp(object sender, MouseEventArgs e)
{
MoveCP = 0;
}
private void ControlPanel_MouseMove(object sender, MouseEventArgs e)
{
if (MoveCP == 1)
{
SetDesktopLocation(MousePosition.X - MapX, MousePosition.Y - MapY);
}
}
private void Exit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void Minimize_Click(object sender, System.EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private bool ValidEmail(string email)
{
string pattern = @"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$";
return Regex.IsMatch(email, pattern);
}
private void Join_button_Click(object sender, System.EventArgs e)
{
string username = Username_textbox.Text;
string password = Password_textbox.Text;
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
MessageBox.Show("Kullanıcı adı ve şifre alanları boş olamaz!");
return;
}
if (!ValidEmail(username))
{
MessageBox.Show("Geçerli bir eposta adresi girin!");
return;
}
try
{
conn.Open();
string query = "SELECT * FROM Users WHERE username = @username";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@username", username);
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
string savedPassword = reader["password"].ToString();
bool isAdmin = (bool)reader["isadmin"];
if (savedPassword == password)
{
Properties.Settings.Default.Username = username;
Properties.Settings.Default.Password = password;
Properties.Settings.Default.Save();
DialogResult goadmin = MessageBox.Show("Admin ekranı için EVET / Ana ekran için HAYIR", "PASPAS - Onay", MessageBoxButtons.YesNo);
if (isAdmin && goadmin == DialogResult.Yes)
{
Admin admin = new Admin();
admin.Show();
}
else
{
Main main = new Main();
main.Show();
}
}
}
}
else if (!reader.HasRows)
{
reader.Close();
string insertUserQuery = "INSERT INTO Users (username, password, creationtime) VALUES (@username, @password, GETDATE())";
SqlCommand insertUserCmd = new SqlCommand(insertUserQuery, conn);
insertUserCmd.Parameters.AddWithValue("@username", username);
insertUserCmd.Parameters.AddWithValue("@password", password);
insertUserCmd.ExecuteNonQuery();
insertUserCmd.Dispose();
string insertSettingsQuery = "INSERT INTO UserSettings (username) VALUES (@username)";
SqlCommand insertSettingsCmd = new SqlCommand(insertSettingsQuery, conn);
insertSettingsCmd.Parameters.AddWithValue("@username", username);
insertSettingsCmd.ExecuteNonQuery();
insertSettingsCmd.Dispose();
MessageBox.Show("Kayıt olundu.");
}
string usersettingsQuery = "SELECT * FROM UserSettings WHERE username = @username";
SqlCommand usersettingsCmd = new SqlCommand(usersettingsQuery, conn);
usersettingsCmd.Parameters.AddWithValue("@username", username);
reader.Close();
SqlDataReader usersettingsReader = usersettingsCmd.ExecuteReader();
if (usersettingsReader.HasRows)
{
while (usersettingsReader.Read())
{
Properties.Settings.Default.Username = (string)usersettingsReader["username"];
Properties.Settings.Default.Clipboard = (bool)usersettingsReader["Clipboard"];
Properties.Settings.Default.TemporaryFiles = (bool)usersettingsReader["TemporaryFiles"];
Properties.Settings.Default.DownloadedInstallations = (bool)usersettingsReader["DownloadedInstallations"];
Properties.Settings.Default.RecentlyUsed = (bool)usersettingsReader["RecentlyUsed"];
Properties.Settings.Default.PreviewCache = (bool)usersettingsReader["PreviewCache"];
Properties.Settings.Default.DNSCache = (bool)usersettingsReader["DNSCache"];
Properties.Settings.Default.Logs = (bool)usersettingsReader["Logs"];
Properties.Settings.Default.SystemCache = (bool)usersettingsReader["SystemCache"];
Properties.Settings.Default.MemoryDumps = (bool)usersettingsReader["MemoryDumps"];
Properties.Settings.Default.Prefetch = (bool)usersettingsReader["Prefetch"];
Properties.Settings.Default.FontCache = (bool)usersettingsReader["FontCache"];
Properties.Settings.Default.DownloadCache = (bool)usersettingsReader["DownloadCache"];
Properties.Settings.Default.OldWindows = (bool)usersettingsReader["OldWindows"];
Properties.Settings.Default.DarkMode = (bool)usersettingsReader["DarkMode"];
Properties.Settings.Default.Save();
}
}
else
{
MessageBox.Show("Kullanıcı ayarları bulunamadı!");
}
reader.Close();
usersettingsReader.Close();
Username_textbox.Text = "";
Password_textbox.Text = "";
}
conn.Close();
}
catch (Exception ex)
{
Database_error.Visible = true;
MessageBox.Show(ex.ToString());
}
}
private void Auth_Load(object sender, System.EventArgs e)
{
try
{
connectionStatus_Tick(null, null);
connectionStatus.Start();
}
catch
{
Database_error.Visible = true;
}
}
private void connectionStatus_Tick(object sender, System.EventArgs e)
{
try
{
using (SqlConnection testconn = new SqlConnection("Data Source=YOURSERVERNAME;Initial Catalog=PASPAS;Persist Security Info=true;User ID=sa;Password=1"))
{
testconn.Open();
if (testconn.State == ConnectionState.Open)
{
Label_statuslive.ForeColor = Color.LimeGreen;
Label_statuslive.Text = "Online (" + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + ")";
}
else
{
Label_statuslive.ForeColor = Color.Red;
Label_statuslive.Text = "Status (Disconnected)";
}
}
}
catch
{
Label_statuslive.ForeColor = Color.Red;
Label_statuslive.Text = "Status (Disconnected)";
}
}
}
}