I am writing an access control program in Java that captures passwords using JPasswordField. Since the jpasswordfield.getPassword() method returns values as chars, I need to know how to save the char value in a MYSQL database using preparedstatement. I am using MYSQL fields password char[100] for storing the passwords.
Please help.
I made a simple example of storing a char array in a database using a prepared statement. I used Java DB instead of MySQL as it is included in the JDK (jdk1.7.0/db/lib/derby.jar) it shouldn’t matter for this example.
As others already said, you should not store passwords in plaintext in the database. Instead you should store a hash of it (SHA-1 Hash in Java).