Esempio n. 1
0
  public static String digestHashOldFunnyHex(String hashType, String str) {
    if (UtilValidate.isEmpty(hashType)) hashType = "SHA";
    if (str == null) return null;
    try {
      MessageDigest messagedigest = MessageDigest.getInstance(hashType);
      byte[] strBytes = str.getBytes();

      messagedigest.update(strBytes);
      return oldFunnyHex(messagedigest.digest());
    } catch (Exception e) {
      Debug.logError(e, "Error while computing hash of type " + hashType, module);
    }
    return str;
  }
Esempio n. 2
0
 private static boolean doCompareTypePrefix(String crypted, String defaultCrypt, byte[] bytes) {
   int typeEnd = crypted.indexOf("}");
   String hashType = crypted.substring(1, typeEnd);
   String hashed = crypted.substring(typeEnd + 1);
   MessageDigest messagedigest = getMessageDigest(hashType);
   messagedigest.update(bytes);
   byte[] digestBytes = messagedigest.digest();
   char[] digestChars = Hex.encodeHex(digestBytes);
   String checkCrypted = new String(digestChars);
   if (hashed.equals(checkCrypted)) {
     return true;
   }
   // This next block should be removed when all {prefix}oldFunnyHex are fixed.
   if (hashed.equals(oldFunnyHex(digestBytes))) {
     Debug.logWarning(
         "Warning: detected oldFunnyHex password prefixed with a hashType; this is not valid, please update the value in the database with ({%s}%s)",
         module, hashType, checkCrypted);
     return true;
   }
   return false;
 }