java - JDBC: How to store and retrieve hashed passwords -


i'm trying make simple secure login system. i've read hashing , salting passwords gives sufficient security if you're using algorithm hashing , creating unique salt each hash. found code-snippet on owasp website hashing method:

public static byte[] hashpassword(final char[] password, final byte[] salt, final int iterations, final int keylength) {      try {         secretkeyfactory skf = secretkeyfactory.getinstance("pbkdf2withhmacsha512");         pbekeyspec spec = new pbekeyspec(password, salt, iterations, keylength);         secretkey key = skf.generatesecret(spec);         byte[] res = key.getencoded();         return res;      } catch (nosuchalgorithmexception | invalidkeyspecexception e) {         throw new runtimeexception(e);     } } 

and i'm using securerandom generate salt

    public static byte[] generatesalt(int length) {     securerandom random = new securerandom();       byte[] salt = new byte[length];       random.nextbytes(salt);       return salt; } 

this question comes

i store hashed password , salt database using jdbc. i'm not sure datatype use in databse (varchar? blob? else?)

i've tried storing byte array varchar , reading string, when output result question marks, guess that's not way it.

a blob looks right, considering storing bytes. examples find seem use storing images thinking there might approach byte arrays? what's way it?


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -