match two JPasswordFields in keyPress error char length

28 views Asked by At

I am trying to match two JPassWordFields in KeyPress event, when I type the password in the first JPassWordField, it return every letter's value immediately (I printed the char[] output to make sure) but when I type the same password or any password this happens :

at the 1st key stroke, it returns empty char array (e.g if I pressed "e" it returns [])

at the 2nd key stroke, it returns the value of the letter that was pressed at the 1st key stroke (e.g if I pressed "y" it returns "e" the previous letter and the output is [e])

at the 3rd key stroke, it returns the value of the letter that was pressed at the 2nd key stroke (e.g if I pressed "s" it returns "y" the previous letter and the output is [e,y])

and so on ....

so suppose I entered "eysa" as password in the first JPassWordField, I must enter "eysaa" in the second JPassWordField to have a matched char[] output of both

and if I backspace the second password to "eysa" the match status still true -_-

plz help, my head is spinning from lookingn for a sulotion here the keypress event I am using :

private void pfRCodeKeyTyped(java.awt.event.KeyEvent evt) {  

    mat = pfCode.getPassword();
    tmp = pfRCode.getPassword();
    if (!(Arrays.equals(mat,null) || Arrays.equals(tmp,null))) {
        if (!Arrays.equals(tmp, mat)) {
            jLWRC.setForeground(Color.red);
            jLWRC.setText("No Match");
        } else {
            jLWRC.setForeground(Color.green);
            jLWRC.setText("Match, password accepted");
        }
    } else {
        jLWRC.setText("password field Empty");
    }
}                                          
0

There are 0 answers