I'm trying to compare passwords in java coming from a web service.
I invoke the service from command line with the following:
curl -d '[{"usr":"joe","password":"joe"}]' http://mydomain.com:8080/myservice/login
I parse the JSON and pass the password to a hash method.
My hashing method is as follows:
private String createHash(String password){
byte[] bytesOfMessage = null;
try {
bytesOfMessage = password.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String thedigest = md.digest(bytesOfMessage).toString();
System.out.println("passed in: "+thedigest);
return thedigest;
}
The problem is that the hash that is printed is different everytime I invoke this method with the exact same password. How can I have the passwords come out with the same hash so I can compare the passwords and authenticate a user?
Thanks!