Changeset 25318
- Timestamp:
- 2012-03-30T16:37:23+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
r25311 r25318 9 9 import org.w3c.dom.NodeList; 10 10 11 import java.math.BigInteger; 11 12 import java.util.ArrayList; 12 13 import java.util.HashMap; … … 694 695 MessageDigest digest = MessageDigest.getInstance("SHA-1"); 695 696 digest.reset(); 696 hashedPassword = new String(digest.digest(password.getBytes("UTF-8"))); 697 hashedPassword = new String(digest.digest(password.getBytes("US-ASCII"))); // toHex after using ASCII charset will result in acceptable length of hex string 698 hashedPassword = toHex(hashedPassword); // this conversion is required to avoid the strange error of login failure on some legal password strings 697 699 } 698 700 catch (Exception ex) … … 702 704 return hashedPassword; 703 705 } 706 707 708 709 // This method can also be used for printing out the password in hex (in case 710 // the password used the UTF-8 Charset), or the hex values in any unicode string. 711 // From http://stackoverflow.com/questions/923863/converting-a-string-to-hexadecimal-in-java 712 public static String toHex(String arg) { 713 try { 714 return String.format("%x", new BigInteger(arg.getBytes("US-ASCII"))); // set to same charset as used by hashPassword 715 } catch (Exception e) { // UnsupportedEncodingException 716 e.printStackTrace(); 717 } 718 return "Unable to print"; 719 } 720 704 721 705 722 private void checkAdminUserExists()
Note:
See TracChangeset
for help on using the changeset viewer.