how to store passwords in database?
- by rgksugan
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???