I have a login frame, That has two different login mode, "User" and "Admin".
My problem is in admin mode (when select admin from jcombobox),
When i select admin, my first textfield should fill with "Administration" automatically and did, And in my jpasswordfiled, It should search it's password number from text file (that is 2).
But, Not accept in admin mode:
public class LoginFrame extends javax.swing.JFrame implements ActionListener {
private String username;
private char[] Password;
...
private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
username = String.valueOf(jTextField1.getText());
Password = jPasswordField1.getPassword();
if (jComboBox1.getSelectedIndex() == 2) {
if (adminCanGoNext2()) {
goAdminMainPage(); // Execute work
} else {
ErrorMessageLabel.setText("Did Not Match");
}
}
} catch (Exception e) {
ErrorMessageLabel.setText("Enter Correct Input");
}
public boolean adminCanGoNext2() throws IOException {
FileReader fr = new FileReader("LoginInformation.txt");
BufferedReader br = new BufferedReader(fr);
String line;
while( (line = br.readLine())!= null ){
if(line.startsWith("Admin")){
char[] charedPass=line.toCharArray(); // char password that read from file
System.out.println("readed password is: "+ charedPass.toString());
if(Arrays.equals(charedPass, Password)){
return true;
}
}
}
return false;
}
public void goAdminMainPage() {
System.out.println("Go ");
}
...
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jComboBox1) {
if (jComboBox1.getSelectedIndex() == 2) {
jTextField1.setText("Administration");
}
}
}
}
Login Information.txt file:
Admin 2
271 tes tt Male 2013/05/30
458 tttt uuuu Female 2013/05/30
Now, When i select admin mode, my jtextfield1 text is "Administration" perfectly,
But when i try number "2" for passwordfield, and clicked to login button, make no change!