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
Post a Comment