-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangePassInstructor.java
205 lines (164 loc) · 5.29 KB
/
ChangePassInstructor.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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class ChangePassInstructor extends JFrame implements ActionListener, MouseListener{
private JLabel LabelCurrentPass, LabelNewtPass,LabelBackGroundImage;
private JPasswordField CurrentPassPF, NewPassPF;
private JButton buttonPassChange, buttonBack;
private JPanel panel;
private String OldPassword, NewPassword;
private int InstructorId;
private boolean flagPass;
public ChangePassInstructor(int InstructorId)
{
super("Instructor - Password Change Page");
Color lightButton = new Color(71, 92, 150);
Color lightBlue = new Color(172, 166, 255);
this.setSize(600, 650);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
panel = new JPanel();
panel.setLayout(null);
panel.setBackground(Color.WHITE);
ImageIcon img = new ImageIcon("icon.jpg");
this.setIconImage(img.getImage());
LabelBackGroundImage = new JLabel();
LabelBackGroundImage.setBounds(0,0, 600,200);
ImageIcon imgThisImg = new ImageIcon("logInBackground.JPG");
LabelBackGroundImage.setIcon(imgThisImg);
panel.add(LabelBackGroundImage);
this.InstructorId=InstructorId;
LabelCurrentPass = new JLabel("Enter Current Password :");
LabelCurrentPass.setBounds(110, 200, 180, 25);
LabelCurrentPass.setFont(new Font("Tahoma", Font.PLAIN, 15));
LabelCurrentPass.setForeground(Color.BLACK);
panel.add(LabelCurrentPass);
LabelNewtPass = new JLabel("Enter New Password :");
LabelNewtPass.setBounds(110, 240, 180, 25);
LabelNewtPass.setFont(new Font("Tahoma", Font.PLAIN, 15));
LabelNewtPass.setForeground(Color.BLACK);
panel.add(LabelNewtPass);
CurrentPassPF = new JPasswordField();
CurrentPassPF.setBounds(320, 200, 135, 25);
panel.add(CurrentPassPF);
NewPassPF = new JPasswordField();
NewPassPF.setBounds(320, 240, 135, 25);
panel.add(NewPassPF);
buttonPassChange = new JButton("Change");
buttonPassChange.setBounds(150,300,120,30);
buttonPassChange.setFont(new Font("Ariel", Font.PLAIN, 15));
buttonPassChange.setForeground(Color.BLACK);
buttonPassChange.setBackground(lightButton);
buttonPassChange.addActionListener(this);
buttonPassChange.addMouseListener(this);
panel.add(buttonPassChange);
buttonBack = new JButton("Back");
buttonBack.setBounds(295,300,120,30);
buttonBack.setFont(new Font("Ariel", Font.PLAIN, 15));
buttonBack.setForeground(Color.BLACK);
buttonBack.setBackground(lightButton);
buttonBack.addActionListener(this);
buttonBack.addMouseListener(this);
panel.add(buttonBack);
this.add(panel);
}
public void actionPerformed(ActionEvent ae){}
public void mouseEntered(MouseEvent me){}
public void mouseExited(MouseEvent me){}
public void mouseReleased(MouseEvent me){}
public void mousePressed(MouseEvent me){}
public void mouseClicked(MouseEvent me)
{
JButton b = (JButton) me.getComponent();
if(b==buttonPassChange)
{
OldPassword=CurrentPassPF.getText();
System.out.println(OldPassword);
NewPassword=NewPassPF.getText();
Check();
if(flagPass)
{
UpdatePass();
}
else
{
JOptionPane.showMessageDialog(this,"Current Password Wrong!!"+"\n"+" Try Again");
}
}
else if(b==buttonBack)
{
InstructorHome home = new InstructorHome(InstructorId);
try{
this.setVisible(false);
home.setVisible(true);
}catch(Exception ex){}
}
}
public void Check()
{
System.out.println("Changing Pass for InstructorId: "+InstructorId);
String queryPassCheck = "SELECT `Password` FROM accounts WHERE UserId ="+ InstructorId+";";
Connection con=null;
Statement st = null;
ResultSet rs = null;
System.out.println(queryPassCheck);
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
rs = st.executeQuery(queryPassCheck);
System.out.println("results received");
while(rs.next())
{
String CurrentPass = rs.getString("Password");;
if(OldPassword.equals(CurrentPass))
{
flagPass=true;
System.out.println("Pass Match");
}
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void UpdatePass()
{
Connection con =null;
Statement st = null;
String queryForUpdate = "UPDATE accounts SET Password= '"+NewPassword+"' where UserId="+InstructorId;
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/Group8F","root","");
System.out.println("connection done");
st = con.createStatement();
System.out.println("statement created");
st.executeUpdate(queryForUpdate);
st.close();
con.close();
Back();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,"Password Must Less Than 11 Character");
System.out.println(e.getMessage());
}
}
public void Back()
{
JOptionPane.showMessageDialog(this,"Password Changed Success");
flagPass=false;
InstructorHome home = new InstructorHome(InstructorId);
try{
this.setVisible(false);
home.setVisible(true);
}catch(Exception ex){}
}
}