how to store passwords in database?

Posted by rgksugan on Stack Overflow See other posts from Stack Overflow or by rgksugan
Published on 2010-06-03T06:00:37Z Indexed on 2010/06/03 6:04 UTC
Read the original article Hit count: 248

Filed under:
|
|

I use jsp and servlets in my web application. i need to store passwords in the database. I found that hashing will be the best way to do that. I used this code to do it.

                java.security.MessageDigest d = null;
                d = java.security.MessageDigest.getInstance("SHA-1");
                d.reset();
                d.update(pass.getBytes("UTF-8"));
                byte b[] = d.digest();
                String tmp = (new BASE64Encoder()).encode(b);

When i tried to print the value of tmp, i get some other value.i guess its the hash value of the password. But when i persist this data to the database the original password gets saved there other than the value in tmp..

What is the problem???

© Stack Overflow or respective owner

Related posts about java

Related posts about password