-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
255 lines (222 loc) · 8.22 KB
/
Program.cs
File metadata and controls
255 lines (222 loc) · 8.22 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
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
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
namespace Project_Authentication;
class Program
{
public static List<User> banyakUsers = new List<User>();
static void Main()
{
Menu();
}
static void Menu()
{
bool key = true;
do
{
string[] menuTampilan = { "Create", "Show", "Login", "Exit" };
Console.WriteLine("==BASIC AUTHENTICATION==");
for (int i = 0; i < menuTampilan.Length; i++)
{
Console.WriteLine($"{i + 1}. {menuTampilan[i]} User");
}
Pilih();
} while (key);
}
static void Pilih()
{
Console.Write("Input : ");
int pilihMenu = Convert.ToInt32(Console.ReadLine());
switch (pilihMenu)
{
case 1: //CREATE
Create();
break;
case 2: //EDIT
View(banyakUsers);
break;
case 3: //LOGIN
Login();
Console.Clear();
break;
case 4: //EXIT
System.Environment.Exit(0);
break;
default:
Console.Write("\nTidak ada pilihan");
Console.ReadKey();
Console.Clear();
break;
}
}
static void Create()
{
Console.Clear();
User singleUser = new User();
Console.Write("First Name : ");
singleUser.FirstName = Console.ReadLine(); //menentukan First Name
Console.Write("Last Name : ");
singleUser.LastName = Console.ReadLine(); //menentukan Last Name
singleUser.Username = singleUser.FirstName[..2] + singleUser.LastName.Substring(0, 2); //menentukan Username
bool check = true;
do //menentukan Password
{
Console.Write("Password : ");
string checkPass = Console.ReadLine();
if (checkPass.Length >= 8)
{
if (checkPass.Any(char.IsUpper))
{
if (checkPass.Any(char.IsLower))
{
if (checkPass.Any(char.IsNumber))
{
singleUser.Password = checkPass;
check = false;
break;
}
}
}
}
Console.WriteLine("\nPassword must have at least 8 characters\r\n with at least one Capital letter, at least one lower case letter and at least one number.\n");
} while (check);
for (int i = 0; i <= banyakUsers.Count; i++)
{
singleUser.Id = i + 1; //menentukan ID
}
banyakUsers.Add(singleUser);
Console.Write("\nData user berhasil dibuat");
Console.ReadKey();
Console.Clear();
}
static void View(List<User> banyakUsers)
{
bool key = true;
do
{
Console.Clear();
Console.WriteLine("==SHOW USER==");
foreach (User item in banyakUsers)
{
Console.WriteLine("========================");
Console.WriteLine($"ID\t: {item.Id}");
Console.WriteLine($"Name\t: {item.FirstName} {item.LastName}");
Console.WriteLine($"Username: {item.Username}");
Console.WriteLine($"Password: {item.Password}");
Console.WriteLine("========================");
}
Console.WriteLine("\nMenu");
string[] menuEdit = { "Edit User", "Delete User", "Back" };
for (int i = 0; i < menuEdit.Length; i++)
{
Console.WriteLine($"{i + 1}. {menuEdit[i]}");
}
Console.Write("Input : ");
int pilihEdit = Convert.ToInt16(Console.ReadLine());
switch (pilihEdit)
{
case 1:
bool kunci = true;
do
{
Console.Write("\nID yang ingin diubah: ");
int ubahId = Convert.ToInt32(Console.ReadLine());
foreach (User item in banyakUsers)
{
if (ubahId == item.Id)
{
Console.Write("First Name : ");
string ubahFirst = Console.ReadLine();
item.FirstName = ubahFirst;
Console.Write("Last Name : ");
string ubahLast = Console.ReadLine();
item.LastName = ubahLast;
item.Username = item.FirstName[..2] + item.LastName.Substring(0, 2);
bool check = true;
do
{
Console.Write("Password : ");
string ubahPass = Console.ReadLine();
if (ubahPass.Length >= 8)
{
if (ubahPass.Any(char.IsUpper))
{
if (ubahPass.Any(char.IsLower))
{
if (ubahPass.Any(char.IsNumber))
{
item.Password = ubahPass;
check = false;
break;
}
}
}
}
Console.WriteLine("\nPassword must have at least 8 characters\r\n with at least one Capital letter, at least one lower case letter and at least one number.\n");
} while (check);
Console.Write("\nUser sudah berhasil diedit");
kunci = false;
Console.ReadKey();
goto Selesai;
}
}
Console.Write("\nUser tidak ditemukan !!!\n");
Console.ReadKey();
break;
Selesai:;
} while (kunci);
break;
case 2:
Console.Write("\nID yang ingin dihapus: ");
int hapusId = Convert.ToInt32(Console.ReadLine());
foreach (User item in banyakUsers.ToArray())
{
if (hapusId == item.Id)
{
banyakUsers.Remove(item);
break;
}
}
Console.Write("\nUser sudah berhasil dihapus");
Console.ReadKey();
break;
case 3:
key = false;
Console.Clear();
break;
default:
Console.Write("\nTidak ada pilihan");
Console.ReadKey();
break;
}
} while (key);
}
static void Login()
{
Console.Clear();
Console.WriteLine("==LOGIN==");
Console.Write("USERNAME : ");
string inputUser = Console.ReadLine();
Console.Write("PASSWORD : ");
string inputPass = Console.ReadLine();
bool status = false;
foreach (var item in banyakUsers)
{
if (item.Username == inputUser && item.Password == inputPass)
{
status = true;
break;
}
}
if (status == true)
{
Console.Write("Login Berhasil");
Console.ReadKey();
}
else
{
Console.Write("Login Gagal");
Console.ReadKey();
}
}
}