I have a .jsp
which accepts password input. It will not match the hash of a password inside the application, even though a test using attempt.equals(password)
works prior to the hashing.
I am passing the string thus:
PasswordManager.checkPassword(request.getParameter("password"))
This is my hashing code:
byte[]开发者_如何学JAVA password = p.getBytes("UTF-8");
byte[] attempt = a.getBytes("UTF-8");
passwordHash = DigestUtils.md5(password);
attemptHash = DigestUtils.md5(attempt);
In addition, I have set the encoding in the .jsp
:
<fmt:requestEncoding value="UTF-8" />
However, the hashes remain stubbornly different. Any ideas?
Those values suggest to me that perhaps toString() isn't overloaded. Are you calling toString on the byte arrays? If yes, those are the hash codes of two different objects.
Try this:
byte[] password = p.getBytes("UTF-8");
byte[] attempt = a.getBytes("UTF-8");
passwordHash = DigestUtils.md5(password);
attemptHash = DigestUtils.md5(attempt);
System.out.println(new String(passwordHash));
System.out.println(new String(attemptHash));
See if they are the same values this way.
精彩评论