Unable to store SHA hash

From: "Jerry Reid" <jereid(at)hotmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Unable to store SHA hash
Date: 2001-05-03 05:11:09
Message-ID: F75U6Ny5Zrc8BkeDs9P0000e6b2@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

<html><DIV>I apologize if this message appears in duplicate. The original was posted before the I received notice that an additional confirmation message would be needed to get onto the list.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I recently migrated an application from Oracle to Postgresql 7.1. The<BR>migration was fairly painless with one exception:<BR><BR>User's passwords are hashed using SHA, then stored in the database. Ie.<BR>&nbsp;&nbsp;&nbsp; // Get the hash of the password<BR>&nbsp;&nbsp;&nbsp; MessageDigest md=null;<BR>&nbsp;&nbsp;&nbsp; try {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; md = MessageDigest.getInstance("sha");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; catch (NoSuchAlgorithmException e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("Error: sha encryption unavailable.");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; String hashedPass = new<BR>String(md.digest(request.getParameter("pass").getBytes()));<BR><BR>This string contains several characters that are outside the normal ASCII<BR>range. The string could be stored and retrieved using Oracle and MySQL, but<BR>in Postgres any unusual characters become '?'. This corrupts the hash and<BR>prevents users from logging on.<BR><BR>So far, the following have been tried:<BR>- Password stored using PreparedStatement setString() call. Retrieved using<BR>ResultSet.getString(). Verified hash corruption in the database.<BR>- Password field datatype changed from varchar to bytea. Oddly enough,<BR>PreparedStatement.setBytes() can not be used against this datatype. Resorted<BR>to using .setString(). Hash was still corrupted at the database level.<BR><BR>Any insight into how to accomplish this task would be greatly appreciated.<BR><BR>Jerry<BR></DIV><br clear=all><hr>Get Your Private, Free E-mail from MSN Hotmail at <a href="http://www.hotmail.com">http://www.hotmail.com</a>.<br></p></html>

Attachment Content-Type Size
unknown_filename text/html 1.8 KB

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jerry Reid 2001-05-03 05:17:32 Unable to store SHA hash (Non-HTML--Sorry)
Previous Message David Esposito 2001-05-02 21:53:37 getScale() and getPrecision() patch