-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm_SignUp.java
More file actions
670 lines (585 loc) · 30.9 KB
/
Copy pathForm_SignUp.java
File metadata and controls
670 lines (585 loc) · 30.9 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
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package Rent_Rover;
import Rent_Rover.DataBases.DB;
import java.awt.Cursor;
import java.awt.Image;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.mindrot.jbcrypt.BCrypt;
/**
*
* @author PC MOD NEPAL
*/
public class Form_SignUp extends javax.swing.JFrame {
private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(Form_SignUp.class.getName());
/**
* Creates new form Form_Login
*/
public Form_SignUp() {
initComponents();
this.setLocationRelativeTo(null);//center the form
//display images on the jLabels
// brandLogo.setIcon(new javax.swing.ImageIcon (getClass().getResource("images/logo.jpg")));
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jOptionPane1 = new javax.swing.JOptionPane();
jPanel1 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
Close = new javax.swing.JLabel();
jPanel4 = new Rent_Rover.CoolPanel(30);
topic = new javax.swing.JLabel();
UsernameField = new javax.swing.JTextField();
PasswordField = new javax.swing.JPasswordField();
SignUpButton = new javax.swing.JButton();
showpassword = new javax.swing.JCheckBox();
Username = new javax.swing.JLabel();
Password = new javax.swing.JLabel();
SignUpPanel = new javax.swing.JPanel();
alreadyHave = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
mailfield = new javax.swing.JTextField();
pfps = new javax.swing.JLabel();
pfpchoose = new javax.swing.JLabel();
welcomeTo1 = new javax.swing.JLabel();
RentRover = new javax.swing.JLabel();
Cross = new javax.swing.JButton();
RRR = new javax.swing.JLabel();
brandLogo = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);
jPanel1.setBackground(new java.awt.Color(255, 153, 0));
jPanel1.setForeground(new java.awt.Color(255, 255, 255));
jPanel1.setPreferredSize(new java.awt.Dimension(1366, 768));
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
jPanel3.setPreferredSize(new java.awt.Dimension(1366, 768));
jPanel3.setLayout(null);
Close.setFont(new java.awt.Font("Verdana", 0, 48)); // NOI18N
Close.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Close.setText("X");
jPanel3.add(Close);
Close.setBounds(1850, 30, 50, 50);
jPanel4.setBackground(new java.awt.Color(0, 0, 0,100));
topic.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
topic.setForeground(new java.awt.Color(255, 255, 255));
topic.setText("SignUp");
UsernameField.setForeground(new java.awt.Color(102, 102, 102));
UsernameField.setText("example123");
UsernameField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
UsernameFieldFocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
UsernameFieldFocusLost(evt);
}
});
UsernameField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
UsernameFieldActionPerformed(evt);
}
});
PasswordField.setForeground(new java.awt.Color(102, 102, 102));
PasswordField.setText("password");
PasswordField.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
PasswordFieldFocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
PasswordFieldFocusLost(evt);
}
});
SignUpButton.setBackground(new java.awt.Color(0, 153, 255));
SignUpButton.setFont(new java.awt.Font("Modern No. 20", 0, 24)); // NOI18N
SignUpButton.setForeground(new java.awt.Color(255, 255, 255));
SignUpButton.setText("SignUp");
SignUpButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
SignUpButtonMouseEntered(evt);
}
});
SignUpButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SignUpButtonActionPerformed(evt);
}
});
showpassword.setBackground(new java.awt.Color(255, 255, 255));
showpassword.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
showpassword.setForeground(new java.awt.Color(255, 255, 255));
showpassword.setText("Show Password");
showpassword.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showpasswordActionPerformed(evt);
}
});
Username.setFont(new java.awt.Font("Lucida Fax", 0, 14)); // NOI18N
Username.setForeground(new java.awt.Color(255, 255, 255));
Username.setText("Username");
Password.setFont(new java.awt.Font("Lucida Fax", 0, 14)); // NOI18N
Password.setForeground(new java.awt.Color(255, 255, 255));
Password.setText("Password");
SignUpPanel.setBackground(new java.awt.Color(0, 102, 204));
javax.swing.GroupLayout SignUpPanelLayout = new javax.swing.GroupLayout(SignUpPanel);
SignUpPanel.setLayout(SignUpPanelLayout);
SignUpPanelLayout.setHorizontalGroup(
SignUpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);
SignUpPanelLayout.setVerticalGroup(
SignUpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 8, Short.MAX_VALUE)
);
alreadyHave.setFont(new java.awt.Font("Tw Cen MT", 0, 12)); // NOI18N
alreadyHave.setForeground(new java.awt.Color(0, 153, 204));
alreadyHave.setText("already have an account?");
alreadyHave.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
alreadyHaveMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
alreadyHaveMouseEntered(evt);
}
});
jLabel1.setFont(new java.awt.Font("Lucida Fax", 0, 14)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("e-mail");
mailfield.setForeground(new java.awt.Color(153, 153, 153));
mailfield.setText("abc@gmail.com");
mailfield.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
mailfieldFocusGained(evt);
}
public void focusLost(java.awt.event.FocusEvent evt) {
mailfieldFocusLost(evt);
}
});
mailfield.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mailfieldActionPerformed(evt);
}
});
pfps.setBackground(new java.awt.Color(102, 255, 102));
pfps.setOpaque(true);
pfpchoose.setFont(new java.awt.Font("SansSerif", 0, 12)); // NOI18N
pfpchoose.setForeground(new java.awt.Color(0, 204, 255));
pfpchoose.setText("Choose a profile pic");
pfpchoose.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
pfpchoose.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
pfpchooseMouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addComponent(SignUpPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(topic, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(147, 147, 147))
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(UsernameField, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(mailfield, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
.addComponent(Username, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(32, Short.MAX_VALUE))
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(Password, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(alreadyHave))
.addComponent(SignUpButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
.addComponent(showpassword)
.addGap(44, 44, 44)
.addComponent(pfps, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(pfpchoose, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(PasswordField, javax.swing.GroupLayout.Alignment.LEADING))
.addGap(32, 32, 32))))
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(topic)
.addGap(18, 18, 18)
.addComponent(SignUpPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mailfield, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(Username, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(UsernameField, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(Password, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(showpassword)
.addGap(0, 28, Short.MAX_VALUE))
.addComponent(pfps, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
.addGroup(jPanel4Layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(pfpchoose)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(SignUpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(alreadyHave)
.addContainerGap())
);
jPanel3.add(jPanel4);
jPanel4.setBounds(820, 90, 450, 500);
welcomeTo1.setFont(new java.awt.Font("Tw Cen MT", 0, 48)); // NOI18N
welcomeTo1.setForeground(new java.awt.Color(255, 255, 255));
welcomeTo1.setText("Welcome to");
jPanel3.add(welcomeTo1);
welcomeTo1.setBounds(120, 170, 240, 60);
RentRover.setFont(new java.awt.Font("Tw Cen MT", 0, 48)); // NOI18N
RentRover.setForeground(new java.awt.Color(0, 153, 204));
RentRover.setText("RentRover");
jPanel3.add(RentRover);
RentRover.setBounds(370, 170, 200, 60);
Cross.setBackground(new java.awt.Color(0, 0, 0,100));
Cross.setFont(new java.awt.Font("Tw Cen MT", 1, 24)); // NOI18N
Cross.setForeground(new java.awt.Color(255, 0, 0));
Cross.setText("X");
Cross.setBorder(null);
Cross.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
CrossMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
CrossMouseEntered(evt);
}
});
Cross.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CrossActionPerformed(evt);
}
});
jPanel3.add(Cross);
Cross.setBounds(1310, 10, 30, 30);
RRR.setFont(new java.awt.Font("Tw Cen MT", 0, 18)); // NOI18N
RRR.setForeground(new java.awt.Color(255, 255, 255));
RRR.setText("Rent, Ride, Repeat!");
jPanel3.add(RRR);
RRR.setBounds(140, 250, 140, 30);
brandLogo.setBackground(new java.awt.Color(92, 165, 238));
brandLogo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ProjectImages/logo.jpg"))); // NOI18N
brandLogo.setOpaque(true);
brandLogo.setPreferredSize(new java.awt.Dimension(1366, 768));
jPanel3.add(brandLogo);
brandLogo.setBounds(0, 0, 1366, 690);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 1350, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 688, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1362, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(14, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(23, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void showpasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showpasswordActionPerformed
if(showpassword.isSelected())
{
PasswordField.setEchoChar((char)0);
}
else
{
PasswordField.setEchoChar('*');
}
}//GEN-LAST:event_showpasswordActionPerformed
private void SignUpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SignUpButtonActionPerformed
String username = UsernameField.getText().trim();
String password = String.valueOf(PasswordField.getPassword()).trim();
String email = mailfield.getText().trim();
PreparedStatement ps;
ResultSet rs;
String query = "SELECT * FROM `users` WHERE `username`=? AND password =?";
// Check empty fields
if(username.isEmpty() || password.isEmpty() || email.isEmpty()) {
CustomPopup.showWarning(this, "All fields are required!", "Input Error");
return;
}
// Check values
if(username.equalsIgnoreCase("example123") && password.equalsIgnoreCase("password")) {
JOptionPane.showMessageDialog(this, "Enter a Valid Username & Password!", "Error", JOptionPane.INFORMATION_MESSAGE);
return;
}
try {
// 🔹 Check admin
ps = DB.getConnection().prepareStatement(query);
ps.setString(1, username);
ps.setString(2, password);
rs = ps.executeQuery();
if(rs.next()) {
JOptionPane.showMessageDialog(this, "Admin Exists moving to login page!", "Already Exists", JOptionPane.INFORMATION_MESSAGE);
new Form_Login().setVisible(true);
this.dispose();
}
else {
// 🔹 Check customer
String query1 = "SELECT * FROM `customer` WHERE `username`=? AND password =?";
ps = DB.getConnection().prepareStatement(query1);
ps.setString(1, username);
ps.setString(2, password);
rs = ps.executeQuery();
if(rs.next()) {
JOptionPane.showMessageDialog(this, "Customer already exists going to login...!", "Already Exists", JOptionPane.INFORMATION_MESSAGE);
new Form_Login().setVisible(true);
this.dispose();
}
else {
// 🔹 Validate username length
if(username.length() > 20 || password.length() > 20) {
CustomPopup.showWarning(this, "Username or Password exceeds 20 characters!", "Exceeded Limit");
return;
}
// 🔹 Validate alphanumeric
if(!username.matches("[a-zA-Z0-9]+") || !password.matches("[a-zA-Z0-9]+")) {
CustomPopup.showWarning(this, "Username and Password can only contain letters and numbers!", "Invalid Input");
return;
}
// 🔹 Validate email
if(!email.endsWith("@gmail.com")) {
CustomPopup.showWarning(this, "Email must end with @gmail.com", "Invalid Email");
return;
}
// 🔹 Check if username exists
String checkQuery = "SELECT * FROM customer WHERE username = ?";
ps = DB.getConnection().prepareStatement(checkQuery);
ps.setString(1, username);
rs = ps.executeQuery();
if(rs.next()) {
CustomPopup.showError(this, "Username already exists. Choose another.", "Error");
return;
}
// 🔹 Hash password before storing
String hashedPassword = BCrypt.hashpw(password, BCrypt.gensalt(12));
// 🔹 Insert into DB
String insertQuery = "INSERT INTO customer(username, password, email, profile_picture) VALUES(?, ?, ?, ?)";
ps = DB.getConnection().prepareStatement(insertQuery);
ps.setString(1, username);
ps.setString(2, hashedPassword);
ps.setString(3, email);
if (profilePicBytes != null) {
ps.setBytes(4, profilePicBytes); // Insert the image
} else {
ps.setNull(4, java.sql.Types.BLOB); // If no image is selected
}
ps.executeUpdate();
// 🔹 Success
CustomPopup.showInfo(this, "Registration Successful! You can now log in.", "Success");
new Form_Login().setVisible(true);
this.dispose();
}
}
}
catch(SQLException ex) {
System.out.println(ex.getMessage());
CustomPopup.showError(this, "Database Error: " + ex.getMessage(), "Error");
}
}//GEN-LAST:event_SignUpButtonActionPerformed
private void UsernameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_UsernameFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_UsernameFieldActionPerformed
private void SignUpButtonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SignUpButtonMouseEntered
SignUpButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // TODO add your handling code here:
}//GEN-LAST:event_SignUpButtonMouseEntered
private void CrossActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CrossActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_CrossActionPerformed
private void CrossMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CrossMouseClicked
this.dispose();
}//GEN-LAST:event_CrossMouseClicked
private void UsernameFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_UsernameFieldFocusGained
//clears text if username ko field is Example123
if (UsernameField.getText().trim().toLowerCase().equals("example123"))
{
UsernameField.setText("");
}
}//GEN-LAST:event_UsernameFieldFocusGained
private void UsernameFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_UsernameFieldFocusLost
if((UsernameField.getText().trim().toLowerCase().equals("example123"))||UsernameField.getText().trim().toLowerCase().equals(""))
{
{
UsernameField.setText("example123");
}
}
}//GEN-LAST:event_UsernameFieldFocusLost
private void PasswordFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_PasswordFieldFocusGained
String password=String.valueOf(PasswordField.getPassword());
if(password.trim().toLowerCase().equals("password"))
{
PasswordField.setText("");
}
}//GEN-LAST:event_PasswordFieldFocusGained
private void PasswordFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_PasswordFieldFocusLost
String password= String.valueOf(PasswordField.getPassword());
if((password.trim().toLowerCase().equals("example123"))||(password.trim().toLowerCase().equals("")))
{
password.trim().toLowerCase().equals("");
{
PasswordField.setText("example123");
}
}
}//GEN-LAST:event_PasswordFieldFocusLost
private void alreadyHaveMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_alreadyHaveMouseEntered
alreadyHave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//alreadyHave.setText("<html><u>Already have an account?</u></html>");
}//GEN-LAST:event_alreadyHaveMouseEntered
private void CrossMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CrossMouseEntered
Cross.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}//GEN-LAST:event_CrossMouseEntered
private void alreadyHaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_alreadyHaveMouseClicked
new Form_Login().setVisible(true);
this.dispose();
}//GEN-LAST:event_alreadyHaveMouseClicked
private void mailfieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mailfieldFocusGained
if (mailfield.getText().trim().toLowerCase().equals("abc@gmail.com"))
{
mailfield.setText("");
}
}//GEN-LAST:event_mailfieldFocusGained
private void mailfieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mailfieldFocusLost
if((mailfield.getText().trim().toLowerCase().equals("abc@gmail.com"))||mailfield.getText().trim().toLowerCase().equals(""))
{
{
mailfield.setText("abc@gmail.com");
}
}
}//GEN-LAST:event_mailfieldFocusLost
private void mailfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mailfieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_mailfieldActionPerformed
private byte[] profilePicBytes = null; // store image bytes for database
private void pfpchooseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pfpchooseMouseClicked
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Select Profile Picture");
// Allow only image files
fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter(
"Image Files", "jpg", "jpeg", "png"
));
int result = fileChooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
java.io.File selectedFile = fileChooser.getSelectedFile();
try {
// Read image into BufferedImage
java.awt.image.BufferedImage img = javax.imageio.ImageIO.read(selectedFile);
// Resize image to fit JLabel pfps
Image scaledImg = img.getScaledInstance(pfps.getWidth(), pfps.getHeight(), Image.SCALE_SMOOTH);
pfps.setIcon(new javax.swing.ImageIcon(scaledImg));
// Convert image to byte array for DB
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
javax.imageio.ImageIO.write(img, "png", baos);
profilePicBytes = baos.toByteArray();
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, "Failed to load image: " + ex.getMessage());
}
}
}//GEN-LAST:event_pfpchooseMouseClicked
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ReflectiveOperationException | javax.swing.UnsupportedLookAndFeelException ex) {
logger.log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> new Form_SignUp().setVisible(true));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel Close;
private javax.swing.JButton Cross;
private javax.swing.JLabel Password;
private javax.swing.JPasswordField PasswordField;
private javax.swing.JLabel RRR;
private javax.swing.JLabel RentRover;
private javax.swing.JButton SignUpButton;
private javax.swing.JPanel SignUpPanel;
private javax.swing.JLabel Username;
private javax.swing.JTextField UsernameField;
private javax.swing.JLabel alreadyHave;
private javax.swing.JLabel brandLogo;
private javax.swing.JLabel jLabel1;
private javax.swing.JOptionPane jOptionPane1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JTextField mailfield;
private javax.swing.JLabel pfpchoose;
private javax.swing.JLabel pfps;
private javax.swing.JCheckBox showpassword;
private javax.swing.JLabel topic;
private javax.swing.JLabel welcomeTo1;
// End of variables declaration//GEN-END:variables
}