Skip to content
Advertisement

Encrypted (base64) password not storing in database hsql

I’m trying to simply store an base64 encripted password in database from an input in Java Web App.

I’m using hsqldb for this and my password column type is varbinary(255). But when I try to store it in database I just get the error below. I even tried to change the type of the password column to BLOB or varchar, but it still gives me the same error. Please help.

The error:

JavaScript

Here’s my Servlet:

JavaScript

This is the PasswordHandler.java class:

JavaScript

Advertisement

Answer

You have defined your password column as varbinary(255). Any character string inserted into this type of column must be in hexadecimal format, for example, cd349956e2. You can use an encoder to convert the password into a binary array, then convert the binary into hexadecimal before insert.

Or you can define the column as varchar(255) to insert the password as a base64 string.

In any case, passwords are not usually stored in database directly, but as a secure hash. For example a SHA-256 hash.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement