Hey all,
I want to store passwords in a postgresql database. Currently I use the
MD5Password class below and I've been developing on windows. I ran into
problems when running my application on linux.
Linux and Windows, with same JDK's (1.5.0), create different encrypted
password strings. So when testing a password created on one platform on
the other, it will fail :(
Is there a way to make the getEncodedPassword method behave the same
regardless of the application being run on windows or linux? And if not,
how could I facilitate platform-independent, easy, not necesarily strong
password encryption?
Thanks in advance for any suggestions,
Ronald
--------------------------------------------------
import java.security.*;
public class MD5Password {
public static String getEncodedPassword(String clearTextPassword)
throws
NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(clearTextPassword.getBytes());
return new String(md.digest());
}
public static boolean testPassword(String clearTextTestPassword,
String encodedActualPassword) throws
NoSuchAlgorithmException {
String encodedTestPassword = MD5Password.getEncodedPassword(
clearTextTestPassword);
return (encodedTestPassword.equals(encodedActualPassword) );
}
}
--------------------------------------------------