-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthenticationUI.java
312 lines (255 loc) · 9.1 KB
/
AuthenticationUI.java
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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Login extends Users implements ActionListener {
Container c;
JLabel usernameLabel;
JLabel l2;
JLabel successLabel;
JLabel passkeylbl;
JTextField user;
JPasswordField pass, passkey;
JButton back1;
JButton logiButton;
JButton ok;
JButton tryAgain;
int flag = 0; // for logiButton confirmation
Login() {
setSize(400, 400);
setLocation(550, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
c = getContentPane();
c.setLayout(null);
back1 = new JButton("Back");
back1.setBounds(5, 5, 70, 25);
c.add(back1);
back1.addActionListener(this);
usernameLabel = new JLabel("Username : ");
l2 = new JLabel("Password : ");
usernameLabel.setBounds(10, 50, 100, 20);
l2.setBounds(10, 100, 100, 20);
c.add(usernameLabel);
c.add(l2);
user = new JTextField();
user.setBounds(120, 50, 120, 20);
c.add(user);
pass = new JPasswordField();
pass.setBounds(120, 100, 120, 20);
c.add(pass);
logiButton = new JButton("Login");
logiButton.setBounds(100, 150, 70, 20);
c.add(logiButton);
logiButton.addActionListener(this);
successLabel = new JLabel("", SwingConstants.CENTER);
successLabel.setBounds(0, 200, 400, 30);
c.add(successLabel);
tryAgain = new JButton("Try Again");
tryAgain.setBounds(75, 250, 90, 20);
c.add(tryAgain);
tryAgain.addActionListener(this);
tryAgain.setVisible(false);
ok = new JButton("Ok");
ok.addActionListener(this);
ok.setVisible(false);
passkey = new JPasswordField();
passkey.setVisible(false);
passkeylbl = new JLabel("", SwingConstants.CENTER);
passkeylbl.setBounds(0, 270, 400, 30);
c.add(passkeylbl);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == back1) {
dispose();
new WelcomeUI();
} else if (e.getSource() == logiButton) {
String username1 = user.getText();
String password = String.valueOf(pass.getPassword());
Users user1 = new Users(username1, password);
int result1 = user1.authentication(1, user1);
if (result1 == 0) {
successLabel.setText("Login Successfull !!");
ok.setBounds(170, 250, 60, 20);
c.add(ok);
ok.setVisible(true);
passkey.setVisible(false);
flag = 0;
} else if (result1 == 1) {
successLabel.setText("User does not exist !! Please Signup");
ok.setBounds(270, 250, 60, 20);
c.add(ok);
ok.setVisible(true);
passkey.setVisible(false);
tryAgain.setVisible(true);
flag = 1;
} else if (result1 == -1) {
successLabel.setText("Password is incorrect !! Please try again");
ok.setBounds(270, 250, 60, 20);
c.add(ok);
ok.setVisible(true);
tryAgain.setVisible(true);
flag = -1;
} else if (result1 == 2) {
successLabel.setText("Enter Admin Passcode : ");
successLabel.setBounds(0, 200, 250, 20);
passkey.setBounds(230, 200, 100, 20);
c.add(passkey);
passkey.setVisible(true);
ok.setBounds(170, 250, 60, 20);
c.add(ok);
ok.setVisible(true);
flag = 2;
}
}
if (e.getSource() == ok) {
if (flag == 0) {
dispose();
ok.setBounds(170, 250, 60, 20);
new MainUI();
} else if (flag == 1) {
dispose();
new SignUp();
} else if (flag == -1) {
dispose();
new WelcomeUI();
} else if (flag == 2) {
String passcode = String.valueOf(passkey.getPassword());
if (passcode.equals("737")) {
dispose();
new AdminUI();
} else {
passkeylbl.setText("Incorrect Passcode");
// disappear after 3 seconds
new Thread() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
passkeylbl.setText("");
}
}.start();
passkey.setText("");
}
}
}
if (e.getSource() == tryAgain) {
dispose();
new Login();
}
}
}
class SignUp extends Users implements ActionListener {
JLabel username_lbl, email_lbl, password_lbl, phone_lbl, gender_lbl, age_lbl, country_lbl, success_lbl;
JPasswordField pass;
JTextField usernameLabel, emaField, pField, ageField, countryField;
JRadioButton male, female, others;
JButton cancel, submit, back, ok;
Container c;
ButtonGroup gen = new ButtonGroup();
SignUp() {
setTitle("Sign Up");
setSize(700, 600);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
c = getContentPane();
c.setLayout(null);
back = new JButton("Back");
back.setBounds(5, 5, 70, 25);
c.add(back);
back.addActionListener(this);
username_lbl = new JLabel("Username : ");
username_lbl.setBounds(20, 50, 100, 20);
c.add(username_lbl);
usernameLabel = new JTextField();
usernameLabel.setBounds(130, 50, 150, 20);
c.add(usernameLabel);
email_lbl = new JLabel("Email : ");
email_lbl.setBounds(20, 100, 100, 20);
c.add(email_lbl);
emaField = new JTextField();
emaField.setBounds(130, 100, 150, 20);
c.add(emaField);
password_lbl = new JLabel("Password : ");
password_lbl.setBounds(20, 150, 100, 20);
c.add(password_lbl);
pass = new JPasswordField();
pass.setBounds(130, 150, 150, 20);
c.add(pass);
phone_lbl = new JLabel("Phone Number");
phone_lbl.setBounds(20, 200, 100, 20);
c.add(phone_lbl);
pField = new JTextField();
pField.setBounds(130, 200, 150, 20);
c.add(pField);
gender_lbl = new JLabel("Gender : ");
gender_lbl.setBounds(20, 250, 100, 20);
c.add(gender_lbl);
male = new JRadioButton("Male");
female = new JRadioButton("Female");
others = new JRadioButton("Others");
male.setBounds(130, 250, 80, 20);
female.setBounds(220, 250, 80, 20);
others.setBounds(310, 250, 80, 20);
male.setSelected(true);
c.add(male);
c.add(female);
c.add(others);
gen.add(male);
gen.add(female);
gen.add(others);
age_lbl = new JLabel("Age : ");
age_lbl.setBounds(20, 300, 100, 20);
c.add(age_lbl);
ageField = new JTextField();
ageField.setBounds(130, 300, 100, 20);
c.add(ageField);
country_lbl = new JLabel("Country : ");
country_lbl.setBounds(20, 350, 100, 20);
c.add(country_lbl);
countryField = new JTextField();
countryField.setBounds(130, 350, 100, 20);
c.add(countryField);
submit = new JButton("Submit");
submit.setBounds(20, 400, 100, 30);
c.add(submit);
submit.addActionListener(this);
success_lbl = new JLabel("", SwingConstants.CENTER);
success_lbl.setBounds(0, 450, 700, 30);
c.add(success_lbl);
ok = new JButton("OK");
ok.setBounds(320, 480, 60, 30);
c.add(ok);
ok.addActionListener(this);
ok.setVisible(false);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String password1 = String.valueOf(pass.getPassword());
String gender;
if (male.isSelected()) {
gender = "male";
} else if (female.isSelected()) {
gender = "female";
} else {
gender = "Others";
}
Users users = new Users(usernameLabel.getText(), emaField.getText(), password1, pField.getText(), gender,
ageField.getText(),
countryField.getText());
authentication(2, users);
if (e.getSource() == submit) {
success_lbl.setText("Registration Successfull !!");
ok.setVisible(true);
} else if (e.getSource() == ok) {
dispose();
new Login();
} else if (e.getSource() == back) {
dispose();
new WelcomeUI();
}
}
}