示例#1
0
 public String encodePassword(String password, Object salt) {
   try {
     return "{CRYPT}" + md5Crypt.crypt(password);
   } catch (NoSuchAlgorithmException e) {
     throw new RuntimeException("No MD5 Algorithm", e);
   }
 }
示例#2
0
  public boolean isPasswordValid(String encPassword, String inputPassword, Object salt) {
    try {
      String encryptedPassword = encPassword;
      if (encryptedPassword.startsWith("{crypt}") || encryptedPassword.startsWith("{CRYPT}")) {
        encryptedPassword = encryptedPassword.substring("{crypt}".length());
      }

      int lastDollar = encryptedPassword.lastIndexOf('$');
      String realSalt = encryptedPassword.substring("$1$".length(), lastDollar);

      String check = md5Crypt.crypt(inputPassword, realSalt);

      return check.equals(encryptedPassword);
    } catch (NoSuchAlgorithmException e) {
      throw new RuntimeException("No MD5 Algorithm", e);
    }
  }