Juan
Juan

Reputation: 532

Using passwordField to connect to mySQL

On my program, I prompt the user for a username and password, and I use passwordField to keep people looking at the screen from seeing it. Now when I use the password to connect to the database what should I use?

java.sql.Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/database", username.getText(), passwordField.getText());

1) .getText() works but its deprecated

2) .getPassword().toString() which maybe the same as .getText() but just longer Otherway?

I do not think that any VITAL information maybe lost using my program, but still would like to do things the right way (or understand why). I thought MD5 was the best way to go incase people sniff the communication.

Upvotes: 0

Views: 260

Answers (1)

Sap
Sap

Reputation: 5291

Two things,

  1. Now a days SHA2xx is considered more secured algorithm
  2. You don't have to worry about the encryption/hashing in this code. Most probably your driver will take care of it by internally hashing your db password.

When you are creating a website, or anything that requires password to go through the wire, that's when you should try hashing(with salt) it and storing it hashed in the database.

Upvotes: 1

Related Questions