I am trying to build a simple login form using Swing in Java. I created a Sample form with two fields.
- usernamefield of type TextField
- passfield of type PasswordField
Now I have a database and in that a login table which has following structure.
username | password
----------------------
abcd | xyz
Also I created a connection to database. and I am able to access table data by using ResultSet. I made an object of database connection called conn. I know that password is stored in the form of char array. so when I try to match password by using following code it does not work.
if(usernamefield.getText() == conn.username && passfield.getPassword().toString == conn.password) {
system.out.println("Correct");
}else {
system.out.println("Incorrect");
}
Above code always go to else block.
I also noticed that passfield.getPassword()
prints the correct password while passfield.getPassword().toString
prints some random characters like [C@76dab03c
How to resolve it?