-
Notifications
You must be signed in to change notification settings - Fork 0
/
NewAccount.cs
345 lines (322 loc) · 13.8 KB
/
NewAccount.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CreateTech
{
public partial class NewAccount : Form
{
private bool enabled = false;
private bool see = false;
int prof = -1;
public NewAccount()
{
InitializeComponent();
}
private void btnCalender_Click(object sender, EventArgs e)
{
if (enabled == false) // Enables the calender
{
calender.Visible = true;
calender.Enabled = true;
btnCalender.Text = "Disable Calender";
enabled = true;
}
else // Disables the calender
{
calender.Visible = false;
calender.Enabled = false;
btnCalender.Text = "Enable Calender";
enabled = false;
}
}
private void calender_ValueChanged(object sender, EventArgs e)
{
txtBirthDate.Text = calender.Value.ToString();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure want to return without completing the sign-up process?", "Warning Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Close();
new frmHome().Show();
}
else
{
MessageBox.Show("Your account application details are still pending.", "Abort Confirmed");
}
}
private void btnComplete_Click(object sender, EventArgs e)
{
if(!IsAllLetters(txtName.Text))
{
MessageBox.Show("Error, Your Name cannot consist of numbers or other characters.Please include letters only in the name field", "Data Notification");
txtName.Focus();
return;
}
if (!IsAllLetters(txtSurname.Text))
{
MessageBox.Show("Error, Your Surname cannot consist of numbers or other characters.Please include letters only in the name field", "Data Notification");
txtSurname.Focus();
return;
}
if (!IsEmailValid(txtemail.Text)) // checks if the email is valid
{
MessageBox.Show("Error, Your email address is invalid. Please retype a correct email address.", "Data Notification");
txtSurname.Focus();
return;
}
if (!IsEmailVerified(txtemail.Text)) // The email is not verified.
return;
if (txtName.Text == "" || txtSurname.Text == "" || txtpassword.Text == "" || txtemail.Text == "" || txtBirthDate.Text == "")
{
MessageBox.Show("Error, Please complete all fields before submitting your account application.", "Warning");
return;
}
else // Password Validation begins here so brace yourself, it's a mess
{
if (txtpassword.TextLength < 8) // 8 character password
{
MessageBox.Show("Error, Your password is too short.Please have an 8 or more character password.", "Data Notification");
txtpassword.Focus();
return;
}
bool letters = IsAllLetters(txtpassword.Text);
bool numbers = IsAllNumbers(txtpassword.Text);
bool specialchar = IsOnlyLettersAndNumbers(txtpassword.Text);
if (letters)
{
txtpassword.Focus(); // Sets the password text box to being highlighted/ focused on
MessageBox.Show("Error, Your password does not contain numbers. Please include letters,numbers and special characters(@,#,$,%) within your password.", "Data Notification");
return;
}
else
if (numbers)
{
MessageBox.Show("Error, Your password does not contain letters. Please use a password with numbers, special characters(@,#,$,%) as well as letters.", "Data Notification");
txtpassword.Focus();
return;
}
else
if (specialchar)
{
MessageBox.Show("Error, Your password does not contain special characters. Please use a password with numbers,special characters(@,#,$,%) as well as letters.", "Data Notification");
txtpassword.Focus();
return;
}
}
if (prof < 0)
{
MessageBox.Show("Error, Please Select a profile picture before you proceed", "Data Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
profilepic.Focus();
return;
}
else
{
//Valid acount creation
foreach(User user in frmHome.userList)
{
if(user.Getemail() ==txtemail.Text)
{
MessageBox.Show($"Error, the email: {txtemail.Text} is already registered under an account.Please choose a different email or reset your password.", "Account creation invalid.",MessageBoxButtons.OK,MessageBoxIcon.Error);
txtemail.Focus();
return;
}
if(user.Getaccountname() == txtUserName.Text)
{
MessageBox.Show($"Error, the account name: {txtUserName.Text} is owned by a CreateIT user.Please choose a different account name.", "Account creation invalid.", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserName.Focus();
return;
}
}
if (MessageBox.Show($"Good day {txtName.Text} {txtSurname.Text},before creating your CreateIT account, please find below the terms of conduct:\nCreateIT is a registered branch of CreateTech Incorporated, while all the assets that you shall interact with were integrated into our system, we do not own any third party system or source software such as and not limited to:Recipes,Online Stores,Digital Artwork and third party information.Even though CreateIT's system algorithm is constructed to cater towards you,The User, user data aquirance complies with various privacy acts.\nYour CreateIT account is interlinked with the CreateIT community so please Adhere to standard online policies.If you encounter any glitches,bugs or system failures along with non complying users, please report this to our help centere [email protected] or +27 172 6953.\nCreateTech may suspend or ban any account or user whom violates the terms of conduct,Do you agree to these terms?.", "Terms of Conduct.",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
User newperson = new User(txtemail.Text, txtSurname.Text, txtName.Text, txtUserName.Text, txtpassword.Text, 'N', prof);
frmHome.userList.Add(newperson);
MessageBox.Show($"Thank you for signing up {txtName.Text} {txtSurname.Text}, your account: {txtUserName.Text} has been created✔.", "Account creation confirmation.");
StreamWriter sw = new StreamWriter("CreateTech.txt", false); //Writes to the file
foreach (User user in frmHome.userList)
{
if (user.Getemail() == frmHome.email)
{
user.Setsaved('N');
}
sw.WriteLine($"{user.Getemail()},{user.Getsurname()},{user.Getname()},{user.Getaccountname()},{user.Getpassword()},{user.Getsaved()},{user.Getprof()}");
}
sw.Close();
new frmHome().Show();
this.Close();
}
else
{
MessageBox.Show($"\aPlease understand that all our customers are required to agree to the terms of conduct before creating an account thus since you do not agree, your account has not been created.Thank you for your time.", "Account creation confirmation.",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
public static bool IsAllLetters(string password)
{
foreach(char c in password) // Checks if the password is only letters
{
if (!Char.IsLetter(c))
{
return false;
}
}
return true;
}
public static bool IsAllNumbers(string password) // Checks if the password is only numbers
{
foreach(char c in password)
{
if(!Char.IsDigit(c))
{
return false;
}
}
return true;
}
public static bool IsOnlyLettersAndNumbers(string password) // Checks if the password has only letters and numbers, no special characters (@,#,$,%)
{
foreach (char c in password)
{
if (!Char.IsLetterOrDigit(c))
{
return false;
}
}
return true;
}
public static bool IsEmailValid(string email) // Checks if the email has only letters and numbers, as well as @ or .
{
foreach (char c in email)
{
if (!Char.IsLetterOrDigit(c) && c!='@'&&c!='.')
{
return false;
}
}
return true;
}
public static bool IsEmailVerified(string email) // Checks if the email has only letters and numbers, as well as @ or .
{
int letters = 0;
int at = 0;
int period = 0;
int numbers = 0;
foreach (char c in email)
{
if (Char.IsLetter(c))
{
++letters;
}
if(c =='@')
{
++at;
}
if (c == '.')
{
++period;
}
else
++numbers;
}
if(letters==0) // No letters in email
{
MessageBox.Show("Error, Your email does not contain letters.Please retype your email correctly.", "Data Notification");
return false;
}
if ((at!=1)||(period<1)) // No period or at, email standards conflict
{
MessageBox.Show("Error, Your email is not valid.Please retype your email correctly.", "Data Notification");
return false;
}
return true;
}
private void eye_Click(object sender, EventArgs e)
{
if (!see) //enable view password feature
{
txtpassword.UseSystemPasswordChar = false;
eye.Image = Properties.Resources.closeeye;
see = true;
}
else // conceal the password
{
txtpassword.UseSystemPasswordChar = true;
eye.Image = Properties.Resources.eye;
see = false;
}
}
private void NewAccount_MouseMove(object sender, MouseEventArgs e)
{
lbltime.Text = DateTime.Now.ToLocalTime().ToShortTimeString(); // Changes the time
}
private void btnClear_Click(object sender, EventArgs e)
{
txtName.Clear();
txtSurname.Clear();
txtpassword.Clear();
txtemail.Clear();
txtBirthDate.Clear();
txtUserName.Clear();
}
private void pictureBox1_Click_1(object sender, EventArgs e)
{
prof = 1;
Program.SetPro(profilepic,prof,profilepic);
}
private void pictureBox4_Click(object sender, EventArgs e)
{
prof = 2;
Program.SetPro(profilepic, prof, profilepic);
}
private void pictureBox3_Click(object sender, EventArgs e)
{
prof = 3;
Program.SetPro(profilepic, prof, profilepic);
}
private void pictureBox2_Click(object sender, EventArgs e)
{
prof = 4;
Program.SetPro(profilepic, prof, profilepic);
}
private void pictureBox7_Click(object sender, EventArgs e)
{
prof = 8;
Program.SetPro(profilepic, prof, profilepic);
}
private void pictureBox6_Click(object sender, EventArgs e)
{
prof = 7;
Program.SetPro(profilepic, prof, profilepic);
}
private void pictureBox5_Click(object sender, EventArgs e)
{
prof = 6;
Program.SetPro(profilepic, prof, profilepic);
}
private void pictureBox8_Click(object sender, EventArgs e)
{
prof = 5;
Program.SetPro(profilepic, prof, profilepic);
}
private void btnExit_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure want to return without completing the sign-up process?", "Warning Question", MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
{
this.Close();
new frmHome().Show();
}
else
{
MessageBox.Show("Your account application details are still pending.", "Abort Confirmed");
}
}
}
}