-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUserPage.java
1098 lines (959 loc) · 50.4 KB
/
UserPage.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
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
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package privacysecurity;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/**
*
* @author user
*/
public class UserPage extends javax.swing.JFrame {
Connection con;
PreparedStatement pst,pst1,pst1_2,pst2,pst2_2,pst3,pst3_2,pst4,pst4_2,pst5,pst5_2,pst6,pst6_2;
ResultSet rs,rs1,rs1_2,rs2,rs2_2,rs3,rs3_2,rs4,rs4_2,rs5,rs5_2,rs6,rs6_2;
int mousepX ;
int mousepY ;
public UserPage() {
initComponents();
setIconImage();
}
void user(String username)
{
Name.setText(username);
}
void userna(String ka)
{
Name.setText(ka);
}
public void close()
{
WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel23 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
LogOut = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox<>();
jLabel5 = new javax.swing.JLabel();
AttackProb = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
Exit = new javax.swing.JLabel();
Name = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setBackground(new java.awt.Color(255, 255, 255));
setForeground(new java.awt.Color(255, 255, 255));
setIconImages(null);
setLocationByPlatform(true);
setUndecorated(true);
addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
formMouseDragged(evt);
}
});
addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
formMousePressed(evt);
}
});
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/Screenshot (153).png"))); // NOI18N
jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(136, 11, -1, -1));
jLabel12.setFont(new java.awt.Font("Segoe UI Semibold", 0, 12)); // NOI18N
jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/icons8_versions_20px.png"))); // NOI18N
jLabel12.setText("v1.0");
jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(551, 489, -1, -1));
jLabel23.setFont(new java.awt.Font("Segoe UI Semibold", 0, 12)); // NOI18N
jLabel23.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/icons8_copyright_20px_1.png"))); // NOI18N
jLabel23.setText("Ioannis Bakomichalis 2020");
jPanel1.add(jLabel23, new org.netbeans.lib.awtextra.AbsoluteConstraints(368, 489, 173, -1));
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
jPanel3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseEntered(java.awt.event.MouseEvent evt) {
jPanel3MouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
jPanel3MouseExited(evt);
}
});
jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
LogOut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/icons8_logout_rounded_left_50px.png"))); // NOI18N
LogOut.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
LogOutMouseClicked(evt);
}
});
jPanel3.add(LogOut, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 49, 46));
jLabel4.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
jLabel4.setText("Logout");
jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel4MouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
jLabel4MouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
jLabel4MouseExited(evt);
}
});
jPanel3.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, 50, 23));
jPanel1.add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(560, 0, 70, 90));
jComboBox1.setFont(new java.awt.Font("Segoe UI Semibold", 0, 18)); // NOI18N
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Name", "Surname", "Address", "PostalCode", "City", "Country" }));
jPanel1.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 210, 130, 30));
jLabel5.setFont(new java.awt.Font("Segoe UI Semibold", 0, 24)); // NOI18N
jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/icons8_search_50px_2.png"))); // NOI18N
jLabel5.setText("Search by");
jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 200, 160, 50));
AttackProb.setBackground(new java.awt.Color(0, 0, 0));
AttackProb.setFont(new java.awt.Font("Segoe UI Semibold", 0, 18)); // NOI18N
AttackProb.setForeground(new java.awt.Color(255, 255, 255));
AttackProb.setText("Attack Probability");
AttackProb.setBorder(null);
AttackProb.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
AttackProbMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
AttackProbMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
AttackProbMouseExited(evt);
}
});
AttackProb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AttackProbActionPerformed(evt);
}
});
jPanel1.add(AttackProb, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 350, 190, 80));
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, -3, 630, 520));
jPanel2.setBackground(new java.awt.Color(20, 20, 20));
jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/logo_size_invert.jpg"))); // NOI18N
Exit.setFont(new java.awt.Font("Segoe UI Semibold", 0, 18)); // NOI18N
Exit.setForeground(new java.awt.Color(255, 255, 255));
Exit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/icons8_exit_30px_2.png"))); // NOI18N
Exit.setText("Exit");
Exit.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
ExitMouseClicked(evt);
}
public void mouseEntered(java.awt.event.MouseEvent evt) {
ExitMouseEntered(evt);
}
public void mouseExited(java.awt.event.MouseEvent evt) {
ExitMouseExited(evt);
}
});
Name.setFont(new java.awt.Font("Segoe UI Semibold", 0, 18)); // NOI18N
Name.setForeground(new java.awt.Color(255, 255, 255));
Name.setIcon(new javax.swing.ImageIcon(getClass().getResource("/privacysecurity/images/icons8_user_30px_1.png"))); // NOI18N
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(82, 82, 82)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Exit)
.addComponent(Name, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jLabel2)))
.addContainerGap(49, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Name)
.addGap(274, 274, 274)
.addComponent(Exit)
.addContainerGap(52, Short.MAX_VALUE))
);
getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void ExitMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitMouseClicked
int a = JOptionPane.showConfirmDialog(this,"Do you want to close the IB App?","Exit",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE );
if (a == JOptionPane.YES_OPTION)
{
System.exit(0);
}
else
{
}
}//GEN-LAST:event_ExitMouseClicked
private void formMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMousePressed
mousepX = evt.getX();
mousepY = evt.getY();
}//GEN-LAST:event_formMousePressed
private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged
int aX = evt.getXOnScreen();
int aY = evt.getYOnScreen();
this.setLocation(aX-mousepX,aY-mousepY);
}//GEN-LAST:event_formMouseDragged
private void ExitMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitMouseEntered
Exit.setForeground(new java.awt.Color(42, 60, 76));
}//GEN-LAST:event_ExitMouseEntered
private void ExitMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ExitMouseExited
Exit.setForeground(new java.awt.Color(255,255,255));
}//GEN-LAST:event_ExitMouseExited
private void LogOutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_LogOutMouseClicked
int a = JOptionPane.showConfirmDialog(this,"Do you want to Exit from your account?","Logout",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if (a==JOptionPane.YES_OPTION)
{
close();
LoginPage b = new LoginPage();
b.setVisible(true);
}
else
{
}
}//GEN-LAST:event_LogOutMouseClicked
private void jPanel3MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel3MouseEntered
jPanel3.setBackground(new java.awt.Color(42, 60, 76));
}//GEN-LAST:event_jPanel3MouseEntered
private void jPanel3MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel3MouseExited
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
}//GEN-LAST:event_jPanel3MouseExited
private void jLabel4MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseEntered
jLabel4.setForeground(new java.awt.Color(42, 60, 76));
}//GEN-LAST:event_jLabel4MouseEntered
private void jLabel4MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseExited
jLabel4.setForeground(new java.awt.Color(0, 0, 0));
}//GEN-LAST:event_jLabel4MouseExited
private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked
int a = JOptionPane.showConfirmDialog(this,"Do you want to Exit from your account?","Logout",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if (a==JOptionPane.YES_OPTION)
{
close();
LoginPage b = new LoginPage();
b.setVisible(true);
}
else
{
}
}//GEN-LAST:event_jLabel4MouseClicked
private void AttackProbMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AttackProbMouseExited
AttackProb.setBackground(new java.awt.Color(0, 0, 0));
}//GEN-LAST:event_AttackProbMouseExited
private void AttackProbMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AttackProbMouseEntered
AttackProb.setBackground(new java.awt.Color(42, 60, 76));
}//GEN-LAST:event_AttackProbMouseEntered
private void AttackProbMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AttackProbMouseClicked
String database= DatabasePage.txtdata.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
if(rs.next())
{
int sum = rs.getInt("count(customerid)");
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
}
if(jComboBox1.getSelectedItem().equals("Name"))
{
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
String Username =LoginPage.txtuser.getText();
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
pst1=con.prepareStatement("select customerName from customers where username=?");
pst1.setString(1, Username);
rs1=pst1.executeQuery();
if (rs.next() && rs1.next())
{
String cm = rs1.getString("customerName");
pst1_2=con.prepareStatement("select count(customerName) from customers where customerName=?");
pst1_2.setString(1, cm );
rs1_2=pst1_2.executeQuery();
System.out.println(cm);
if (rs1_2.next())
{
float sum = rs.getInt("count(customerid)");
float sumname = rs1_2.getInt("count(customerName)");
float name =((sum - sumname)/sum) * 100;
int sum1=(int) sum ;
int sumname1=(int) sumname ;
String b = "The probability of attack on Name is: " +name +"%" ;
String c = "Users of the database are: " +sum1 ;
String d = "The count of Users with the same Name are: " +sumname1 ;
String e = "The name is: " + cm ;
String metric;
if (name>=0 && name<33 )
{
metric="The risk is " +name+". " + "Releasing these data has a negligible privacy risk!" ;
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else if(name>=33 && name<66)
{
metric="The risk is " +name+". " + "Releasing these data may result in a significant privacy risk!";
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
metric= "The risk is " +name +". " + "Releasing these data will result in high privacy risk!";
int risk = JOptionPane.showConfirmDialog(null,metric, "Attention! Are you sure you want to disclose your personal data?",JOptionPane.ERROR_MESSAGE,JOptionPane.YES_NO_OPTION);
if (risk == JOptionPane.YES_OPTION)
{
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
pst1=con.prepareStatement("update customers set customerName='-' where username=? ");
pst1.setString(1, Username);
pst1.executeUpdate();
JOptionPane.showMessageDialog(null,"You have not agree to dispose the high risk attack probability and the value has been deleted from our database!");
ResultPage a =new ResultPage();
a.setVisible(true);
this.dispose();
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
}
//System.out.println("The probability is :" +sum);
//System.out.println("The probability is :" +sumname);
// System.out.println("The probability is: " +name+"%");
}
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if (jComboBox1.getSelectedItem().equals("Address"))
{
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
String Username =LoginPage.txtuser.getText();
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
pst2=con.prepareStatement("select address from customers where username=? ");
pst2.setString(1, Username);
rs2=pst2.executeQuery();
if(rs.next()&& rs2.next())
{
String am = rs2.getString("address");
pst2_2 = con.prepareStatement("select count(address) from customers where address=?");
pst2_2.setString(1, am);
rs2_2=pst2_2.executeQuery();
System.out.println(am);
if(rs2_2.next())
{
float sum = rs.getInt("count(customerid)");
float sumadd = rs2_2.getInt("count(address)");
float add = ((sum - sumadd)/sum) * 100;
int sum1=(int) sum ;
int sumadd1=(int) sumadd ;
String b = "The probability of attack on Address is: " +add +"%";
System.out.println("The probability is :" +add +"%");
String c = "Users of the database are: " +sum1 ;
String d = "The count of Users with the same Address are: " +sumadd1 ;
String e = "The Address is: " + am ;
String metric;
if (add>=0 && add<33 )
{
metric="The risk is " +add+". " + "Releasing these data has a negligible privacy risk!" ;
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else if(add>=33 && add<66)
{
metric="The risk is " +add+". " + "Releasing these data may result in a significant privacy risk!";
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
metric= "The risk is " +add +". " + "Releasing these data will result in high privacy risk!";
int risk = JOptionPane.showConfirmDialog(null,metric, "Are you sure you want to disclose your personal data?",JOptionPane.ERROR_MESSAGE,JOptionPane.YES_NO_OPTION);
if (risk == JOptionPane.YES_OPTION)
{
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
pst2=con.prepareStatement("update customers set address='-' where username=? ");
pst2.setString(1, Username);
pst2.executeUpdate();
JOptionPane.showMessageDialog(null,"You have not agree to dispose the high risk attack probability and the value has been deleted from our database!");
ResultPage a =new ResultPage();
a.setVisible(true);
this.dispose();
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
}
}
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if (jComboBox1.getSelectedItem().equals("City"))
{
String Username =LoginPage.txtuser.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
pst3=con.prepareStatement("select city from customers where username=?");
pst3.setString(1, Username);
rs3=pst3.executeQuery();
if(rs3.next() && rs.next())
{
String bm = rs3.getString("city");
pst3_2=con.prepareStatement("select count(city) from customers where city=?");
pst3_2.setString(1, bm);
rs3_2=pst3_2.executeQuery();
System.out.println(bm);
if(rs3_2.next())
{
float sum = rs.getInt("count(customerid)");
float sumcity = rs3_2.getInt("count(city)");
float city = ((sum - sumcity)/sum) * 100;
int sum1=(int) sum ;
int sumcity1=(int) sumcity ;
System.out.println("The probability is :" +city +"%");
String b = "The probability of attack on City is: " +city +"%";
String c = "Users of the database are: " +sum1 ;
String d = "The count of Users with the same City are: " +sumcity1 ;
String e = "The City is: " +bm ;
String metric;
if (city>=0 && city<33 )
{
metric="The risk is " +city+". " + "Releasing these data has a negligible privacy risk!" ;
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else if(city>=33 && city<66)
{
metric="The risk is " +city+". " + "Releasing these data may result in a significant privacy risk!";
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
metric= "The risk is " +city+". " + "Releasing these data will result in high privacy risk!";
int risk = JOptionPane.showConfirmDialog(null,metric, "Are you sure you want to disclose your personal data?",JOptionPane.ERROR_MESSAGE,JOptionPane.YES_NO_OPTION);
if (risk == JOptionPane.YES_OPTION)
{
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
pst3=con.prepareStatement("update customers set city='-' where username=? ");
pst3.setString(1, Username);
pst3.executeUpdate();
JOptionPane.showMessageDialog(null,"You have not agree to dispose the high risk attack probability and the value has been deleted from our database!");
ResultPage a =new ResultPage();
a.setVisible(true);
this.dispose();
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
}
}
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if (jComboBox1.getSelectedItem().equals("PostalCode"))
{
String Username =LoginPage.txtuser.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
pst4=con.prepareStatement("select postalCode from customers where username=? ");
pst4.setString(1, Username);
rs4=pst4.executeQuery();
if(rs4.next() && rs.next())
{
String dm = rs4.getString("postalCode");
pst4_2=con.prepareStatement("select count(postalCode) from customers where postalCode=?");
pst4_2.setString(1, dm);
rs4_2=pst4_2.executeQuery();
System.out.println(dm);
if(rs4_2.next())
{
float sum = rs.getInt("count(customerid)");
float sumpc = rs4_2.getInt("count(postalCode)");
float pc = ((sum - sumpc)/sum) * 100;
int sum1=(int) sum ;
int sumpc1=(int) sumpc ;
System.out.println("The probability is :" +pc +"%");
String b = "The probability of attack on PostalCode is: " + pc +"%";
String c = "Users of the database are: " +sum1 ;
String d = "The count of Users with the same PostalCode are: " +sumpc1 ;
String e = "The PostalCode is: " +dm ;
String metric;
if (pc>=0 && pc<33 )
{
metric="The risk is " +pc+". " + "Releasing these data has a negligible privacy risk!" ;
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else if(pc>=33 && pc<66)
{
metric="The risk is " +pc+". " + "Releasing these data may result in a significant privacy risk!";
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
metric= "The risk is " +pc+". " + "Releasing these data will result in high privacy risk!";
int risk = JOptionPane.showConfirmDialog(null,metric, "Are you sure you want to disclose your personal data?",JOptionPane.ERROR_MESSAGE,JOptionPane.YES_NO_OPTION);
if (risk == JOptionPane.YES_OPTION)
{
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
pst4=con.prepareStatement("update customers set postalCode='-' where username=? ");
pst4.setString(1, Username);
pst4.executeUpdate();
JOptionPane.showMessageDialog(null,"You have not agree to dispose the high risk attack probability and the value has been deleted from our database!");
ResultPage a =new ResultPage();
a.setVisible(true);
this.dispose();
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
}
}
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if (jComboBox1.getSelectedItem().equals("Country"))
{
String Username =LoginPage.txtuser.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
pst5=con.prepareStatement("select country from customers where username=? ");
pst5.setString(1, Username);
rs5=pst5.executeQuery();
if(rs5.next() && rs.next())
{
String em = rs5.getString("country");
pst5_2=con.prepareStatement("select count(country) from customers where country=?");
pst5_2.setString(1, em);
rs5_2=pst5_2.executeQuery();
if(rs5_2.next())
{
float sum = rs.getInt("count(customerid)");
float sumcountry = rs5_2.getInt("count(country)");
float country = ((sum - sumcountry)/sum) * 100;
int sum1=(int) sum ;
int sumcountry1=(int) sumcountry ;
System.out.println("The probability is :" +country +"%");
String b = "The probability of attack on Country is: " + country +"%";
String c = "Users of the database are: " +sum1 ;
String d = "The count of Users with the same Country are: " +sumcountry1 ;
String e = "The Country is: " +em ;
String metric;
if (country>=0 && country<33 )
{
metric="The risk is " +country+". " + "Releasing these data has a negligible privacy risk!" ;
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else if(country>=33 && country<66)
{
metric="The risk is " +country+". " + "Releasing these data may result in a significant privacy risk!";
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
metric= "The risk is " +country+". " + "Releasing these data will result in high privacy risk!";
int risk = JOptionPane.showConfirmDialog(null,metric, "Are you sure you want to disclose your personal data?",JOptionPane.ERROR_MESSAGE,JOptionPane.YES_NO_OPTION);
if (risk == JOptionPane.YES_OPTION)
{
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
pst5=con.prepareStatement("update customers set country='-' where username=? ");
pst5.setString(1, Username);
pst5.executeUpdate();
JOptionPane.showMessageDialog(null,"You have not agree to dispose the high risk attack probability and the value has been deleted from our database!");
ResultPage a =new ResultPage();
a.setVisible(true);
this.dispose();
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
}
}
}
} catch (ClassNotFoundException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(UserPage.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if (jComboBox1.getSelectedItem().equals("Surname"))
{
String Username =LoginPage.txtuser.getText();
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/"+database,"root","");
pst=con.prepareStatement("select count(customerid) from customers");
rs=pst.executeQuery();
pst6=con.prepareStatement("select customerSurname from customers where username=? ");
pst6.setString(1, Username);
rs6=pst6.executeQuery();
if(rs6.next() && rs.next())
{
String fm = rs6.getString("customerSurname");
pst6_2=con.prepareStatement("select count(customerSurname) from customers where customerSurname=?");
pst6_2.setString(1, fm);
rs6_2=pst6_2.executeQuery();
System.out.println(fm);
if(rs6_2.next())
{
float sum = rs.getInt("count(customerid)");
float sumsur = rs6_2.getInt("count(customerSurname)");
float sur = ((sum - sumsur)/sum) * 100;
int sum1=(int) sum ;
int sumsur1=(int) sumsur ;
System.out.println("The probability is :" +sur +"%");
String b = "The probability of attack on Surname is: " + sur +"%";
String c = "Users of the database are: " +sum1 ;
String d = "The count of Users with the same Surname are: " +sumsur1 ;
String e = "The Surname is: " +fm ;
String metric;
if (sur>=0 && sur<33 )
{
metric="The risk is " +sur+". " + "Releasing these data has a negligible privacy risk!" ;
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else if(sur>=33 && sur<66)
{
metric="The risk is " +sur+". " + "Releasing these data may result in a significant privacy risk!";
JOptionPane.showMessageDialog(this, metric);
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else
{
metric= "The risk is " +sur+". " + "Releasing these data will result in high privacy risk!";
int risk = JOptionPane.showConfirmDialog(null,metric, "Are you sure you want to disclose your personal data?",JOptionPane.ERROR_MESSAGE,JOptionPane.YES_NO_OPTION);
if (risk == JOptionPane.YES_OPTION)
{
ResultPage a =new ResultPage();
a.setVisible(true);
this.setVisible(true);
this.setVisible(false);
a.re(b);
a.res(c);
a.resu(d);
a.resul(e);
a.user(Username);
}
else