how to check the password?

Hi, i try to validate the username and the password that i get using a gui menu in a another class. But then it cannot validate the password and it keep on looping to check the username......

my txt file look like this

john;lim;male;12;3;1964;12345;ang mo kio;abc;abc

mary;smith;female;3;11;1950;45678;sengkang;def;def

please tell me the mistakes.... thank u

import java.io.*;

import java.util.*;

import javax.swing.*;

import java.awt.*;

publicclass CustomerDB

{

private String file;

private String delimiter;

private ArrayList customerList;

public CustomerDB(String file, String delimiter)

{

this.file = file;

this.delimiter = delimiter;

try{

loadCustomerData();

}

catch (Exception e){

JOptionPane.showMessageDialog(null, e.getMessage(),"Fatal Error", JOptionPane.ERROR_MESSAGE);

System.exit(-1);

}

}

privatevoid loadCustomerData()throws Exception{

customerList =new ArrayList();

String record;

StringTokenizer tokenizer;

String firstName, lastName, gender, birthDate, birthMonth, birthYear, telephone, address;

char [] password =newchar[10];

char [] confirmPass =newchar[10];

try{

BufferedReader reader =new BufferedReader(new FileReader(file));

record = reader.readLine();

while (record !=null){

tokenizer =new StringTokenizer(record,delimiter);

firstName = tokenizer.nextToken();

lastName = tokenizer.nextToken();

gender = tokenizer.nextToken();

birthDate = tokenizer.nextToken();

birthMonth = tokenizer.nextToken();

birthYear = tokenizer.nextToken();

telephone = tokenizer.nextToken();

address = tokenizer.nextToken();

String password1 = tokenizer.nextToken();

for (int i = 0; i < password1.length(); i++){// putting the password into array of char

password[i] = password1.charAt(i);

}

String confirmPass1 = tokenizer.nextToken();

for (int i = 0; i < confirmPass1.length(); i++){

confirmPass[i] = confirmPass1.charAt(i);

}

customerList.add(new Customer(firstName, lastName, gender, birthDate,

birthMonth, birthYear, telephone, address, password, confirmPass));

record = reader.readLine();

}

reader.close();

}

catch (FileNotFoundException e){

Exception error =new Exception(file +" not found");

throw error;

}

catch (IOException e){

Exception error =new Exception("Error reading " + file);

throw error;

}

catch (NoSuchElementException e){

Exception error =new Exception("Wrong format of " + file);

throw error;

}

}

public ArrayList getCustomerList(){

return customerList;

}

publicboolean validate(String firstName,char [] password){

boolean result =false;

boolean isCorrect =true;

Customer f;

int i = 0;

String inPass =new String (password);

while (result !=true){

f = (Customer) customerList.get(i);

if((f.getFirstName()).equals(firstName)){

System.out.println(f.getFirstName());

JOptionPane.showMessageDialog(null,"Correct ID","Validation", JOptionPane.ERROR_MESSAGE);

//NEED TO CONVERT THE GETPASSWORD TO CHAR

char [] correctPassword = f.getPassword();

System.out.println("After char[]correctPass" + correctPassword);

if(password.length != correctPassword.length){

isCorrect =false;

break;

//System.out.println("password length" + password.length + correctPassword.length + isCorrect);

}

else{

for(int j = 0; j < password.length; j++){

System.out.println("password length 2");

if( password[j] != correctPassword[j] ){

System.out.println("password length 3");

isCorrect =false;

break;

}

}

}

//Zero out the password.

for(int j = 0; j < correctPassword.length; j++ ){

correctPassword[j] = 0;

}

if (isCorrect){

result =true;

JOptionPane.showMessageDialog(null,"Correct id","Validation", JOptionPane.ERROR_MESSAGE);

break;

}

}

i++;

}

return result;

}

publicstaticvoid main(String [] args)

{

CustomerDB f =new CustomerDB("customerData.txt",";");

ArrayList clist = f.getCustomerList();

for (int i = 0; i < clist.size(); i++)

System.out.println((Customer) clist.get(i));

}

}

[8825 byte] By [sas0rizaa] at [2007-10-2 10:31:06]
# 1
Wait... Are you using an array of chars for the passwords? and then looping through the textfile to set them? and then looping through the array to see if it matches another array of chars? You know there's String class for this...
destina at 2007-7-13 2:14:58 > top of Java-index,Java Essentials,Java Programming...
# 2

yeah, i know. i try to use it in this one, but it still gave me the same result. after i read from the password using the public char getPassword() , the password turn out to be char that i dont understand....

public boolean validate(String firstName, char [] password){

boolean result = false;

boolean isCorrect = true;

Customer f;

//int i = 0;

String inPass = new String (password);

//while (result != true){

for (int i = 0; i < customerList.size(); i++){

f = (Customer) customerList.get(i);

if((f.getFirstName()).equals(firstName)){

System.out.println(f.getFirstName());

JOptionPane.showMessageDialog(null, "Correct ID","Validation", JOptionPane.ERROR_MESSAGE);

String pass1 = new String(f.getPassword());

System.out.println(pass1);

if (inPass.equals(pass1)){

JOptionPane.showMessageDialog(null, "Correct pass","Validation", JOptionPane.ERROR_MESSAGE);

result = true;

break;

}

}

}

//}

return result;

}

// in another class call Customer

public char [] getPassword(){

return password;

}

sas0rizaa at 2007-7-13 2:14:58 > top of Java-index,Java Essentials,Java Programming...