This will not fly:
passwordField.getPassword().toString(). equals(confirmPasswordField.getPassword().toString())
It is better to print the results of the .toString() call in a char array to see exactly what I mean.
For example, when I run:
String fooString = "Foo"; char[] fooArray = fooString.toCharArray(); System.out.println(fooArray.toString());
It does not return "Foo" as you seem to expect, but rather a typical and expected representation of the toString() the char array: [ C@19821f . Please note: if you run this, your hash code number will be different from mine (the same if I run it a second time!).
It is better to use the method of the Arrays equals(...) class so that you can compare two char arrays. i.e.,
char[] pw1 = passwordField.getPassword(); char[] pw2 = confirmPasswordField.getPassword(); if (Arrays.equals(pw1, pw2)) {
Note. A bad solution would be to convert the char arrays to a βrealβ string using new String(myCharArray) , but I highly recommend not to do this, as your passwords are very weak and easily broken.
source share