コード例 #1
0
ファイル: CryptFile.java プロジェクト: helma-next/helma-next
  /**
   * @param username ...
   * @param pw ...
   * @return ...
   */
  public boolean authenticate(String username, String pw) {
    if (this.file.exists() && (this.file.lastModified() > this.lastRead)) {
      readFile();
    } else if (!this.file.exists() && (this.users.size() > 0)) {
      this.users.clear();
    }

    String realpw = this.users.getProperty(username);

    if (realpw != null) {
      try {
        // check if password matches
        // first we try with unix crypt algorithm
        String cryptpw = Crypt.crypt(realpw, pw);

        if (realpw.equals(cryptpw)) {
          return true;
        }

        // then try MD5
        if (realpw.equals(DigestUtils.md5(pw))) {
          return true;
        }
      } catch (Exception x) {
        return false;
      }
    } else {
      if (this.parentFile != null) {
        return this.parentFile.authenticate(username, pw);
      }
    }

    return false;
  }
コード例 #2
0
  public String doIclubLogin() {
    LOGGER.info("Class :: " + this.getClass() + " :: Method :: doIclubLogin");
    if (!validateLogin()) {
      try {
        WebClient client =
            IclubWebHelper.createCustomClient(
                BASE_URL
                    + "person/login/"
                    + bean.getLName()
                    + "/"
                    + Base64.encodeBase64URLSafeString(DigestUtils.md5(bean.getLPasswd())));
        ResponseModel response = client.accept(MediaType.APPLICATION_JSON).get(ResponseModel.class);
        client.close();
        if (response.getStatusCode() == 0) {
          setTheme();
          IclubWebHelper.addMessage("Person Logged-In successfully", FacesMessage.SEVERITY_INFO);
          WebClient loginClient =
              IclubWebHelper.createCustomClient(BASE_URL + "person/" + bean.getLName());
          IclubLoginModel model =
              loginClient.accept(MediaType.APPLICATION_JSON).get(IclubLoginModel.class);
          loginClient.close();
          if (model != null && model.getLId() != null) {
            IclubWebHelper.addObjectIntoSession(
                BUNDLE.getString("logged.in.user.id"), model.getIclubPersonBByLPersonId());
            IclubWebHelper.addObjectIntoSession(
                BUNDLE.getString("logged.in.user.scname"), bean.getLName());
            WebClient personClient =
                IclubWebHelper.createCustomClient(
                    U_BASE_URL + "get/" + model.getIclubPersonBByLPersonId());
            IclubPersonModel personModel =
                personClient.accept(MediaType.APPLICATION_JSON).get(IclubPersonModel.class);
            personClient.close();
            IclubWebHelper.addObjectIntoSession(
                BUNDLE.getString("logged.in.user.name"),
                personModel.getPFName()
                    + (personModel.getPLName() == null ? "" : personModel.getPLName() + " "));
            IclubWebHelper.addObjectIntoSession(
                BUNDLE.getString("logged.in.role.id"), model.getIclubRoleType());

            return "/pages/dashboard/user/main.xhtml?faces-redirect=true";

          } else {
            IclubWebHelper.addMessage(
                "Person Profile Fetch Error - Contact Admin", FacesMessage.SEVERITY_ERROR);
            return "";
          }
        } else {
          IclubWebHelper.addMessage(
              "Login error :: " + response.getStatusDesc(), FacesMessage.SEVERITY_ERROR);
          return "";
        }
      } catch (Exception e) {
        LOGGER.error(e, e);
        IclubWebHelper.addMessage("Login error :: " + e.getMessage(), FacesMessage.SEVERITY_ERROR);
        return "";
      }
    } else {
      return "";
    }
  }
コード例 #3
0
ファイル: MiscUtils.java プロジェクト: bazi/kurjun
 /**
  * Calculates the md5 checksum of the given input stream
  *
  * @param is
  * @return md5 checksum, or <code>null</code> if exception occurred
  */
 public static byte[] calculateMd5(InputStream is) {
   byte[] md5 = null;
   try {
     md5 = DigestUtils.md5(is);
   } catch (IOException e) {
   }
   return md5;
 }
コード例 #4
0
  /**
   * Generate the fingerprint of a public key as used by SSH.
   *
   * @param the public key
   * @return an array of bytes containing the fingerprint of the key
   */
  public static final byte[] getKeyFingerprintBytes(final PublicKey key) {
    // Get the serialized version of the key:
    final byte[] keyBytes = getKeyBytes(key);
    if (keyBytes == null) {
      log.error("Can't get key bytes, will return null.");
      return null;
    }

    // The fingerprint is a MD5 digest of the key bytes:
    final byte[] fingerprintBytes = DigestUtils.md5(keyBytes);
    if (log.isDebugEnabled()) {
      log.debug("Fingerprint bytes are " + Hex.encodeHexString(fingerprintBytes) + ".");
    }

    return fingerprintBytes;
  }
コード例 #5
0
  public String updateLogin() {

    try {
      if (validateLoginForm(!updateLogin)) {
        IclubLoginModel model = new IclubLoginModel();
        WebClient client = null;

        if (loginBean.getLId() != null) {
          client = IclubWebHelper.createCustomClient(LOG_BASE_URL + "mod");
          model.setLId(loginBean.getLId());

        } else {
          client = IclubWebHelper.createCustomClient(LOG_BASE_URL + "add");
          model.setLId(UUID.randomUUID().toString());
        }
        model.setLCrtdDt(new Date(System.currentTimeMillis()));
        model = IclubLoginTrans.fromUItoWS(loginBean);

        model.setLPasswd(Base64.encodeBase64URLSafeString(DigestUtils.md5(loginBean.getLPasswd())));
        model.setIclubPersonAByLCrtdBy(bean.getPId());
        model.setIclubPersonBByLPersonId(getSessionUserId());
        model.setIclubRoleType(2l);

        ResponseModel response = null;
        if (updateLogin) {
          response = client.accept(MediaType.APPLICATION_JSON).put(model, ResponseModel.class);
        } else {
          response = client.accept(MediaType.APPLICATION_JSON).post(model, ResponseModel.class);
        }

        if (response.getStatusCode() == 0) {
          IclubWebHelper.addObjectIntoSession("social_update_profile", null);
          IclubWebHelper.addMessage(
              "Personal Details Updated Successfully", FacesMessage.SEVERITY_INFO);
          loadBean = false;
          return "userDashboard";
        } else {
          IclubWebHelper.addMessage(
              "Fail :: " + response.getStatusDesc(), FacesMessage.SEVERITY_ERROR);
        }
      }

    } catch (Exception e) {
      IclubWebHelper.addMessage("Fail :: " + e.getMessage(), FacesMessage.SEVERITY_ERROR);
    }
    return null;
  }
コード例 #6
0
  public void updatePassword() {

    try {
      if (validateLoginForm(!updateLogin)) {
        IclubLoginModel model = new IclubLoginModel();
        WebClient client = null;

        if (loginBean.getLId() != null) {
          client = IclubWebHelper.createCustomClient(BASE_URL + "mod");
          model.setLId(loginBean.getLId());

        } else {
          client = IclubWebHelper.createCustomClient(LOG_BASE_URL + "add");
          model.setLId(UUID.randomUUID().toString());
        }
        model.setLCrtdDt(new Date(System.currentTimeMillis()));
        model.setLLastDate(loginBean.getLLastDate());
        model.setLName(loginBean.getLName());
        model.setLPasswd(Base64.encodeBase64URLSafeString(DigestUtils.md5(loginBean.getLPasswd())));
        model.setLSecAns(loginBean.getLSecAns());
        model.setIclubPersonAByLCrtdBy(bean.getPId());
        model.setIclubPersonBByLPersonId(getSessionUserId());
        model.setIclubRoleType(2l);
        model.setIclubSecurityQuestion(loginBean.getIclubSecurityQuestion());

        ResponseModel response = null;
        if (updateLogin) {
          response = client.accept(MediaType.APPLICATION_JSON).put(model, ResponseModel.class);
        } else {
          response = client.accept(MediaType.APPLICATION_JSON).post(model, ResponseModel.class);
        }

        if (response.getStatusCode() == 0) {
          IclubWebHelper.addMessage(
              "Personal Details Updated Successfully", FacesMessage.SEVERITY_INFO);

        } else {
          IclubWebHelper.addMessage(
              "Fail :: " + response.getStatusDesc(), FacesMessage.SEVERITY_ERROR);
        }
      }

    } catch (Exception e) {
      IclubWebHelper.addMessage("Fail :: " + e.getMessage(), FacesMessage.SEVERITY_ERROR);
    }
  }
コード例 #7
0
ファイル: PasswordCrackerTask.java プロジェクト: msemik/jNode
 @Override
 public Serializable call() throws Exception {
   int i = 0;
   int taskId = System.identityHashCode(this) % 101;
   while (passwordGenerator.hasNext()) {
     String candidateForPassword = passwordGenerator.next();
     if (++i == 1) {
       System.out.println(taskId + " starting cracking since " + candidateForPassword);
     }
     byte[] digest = DigestUtils.md5(candidateForPassword.getBytes());
     if (Arrays.equals(digest, encryptedPassword)) {
       System.out.println("Found password: "******" finishing after " + i + " tries.");
   return "";
 }
コード例 #8
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (resultCode == RESULT_OK) {
     path = data.getData().getPath();
     FileInputStream fis = null;
     try {
       // Generate md5
       fis = new FileInputStream(path);
       String md5String = new String(Hex.encodeHex(DigestUtils.md5(fis)));
       text.setText(md5String);
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     } catch (IOException io) {
       io.printStackTrace();
     }
   }
 }
コード例 #9
0
ファイル: RightscaleTest.java プロジェクト: barnyard/pi
  @Override
  public void testPutObjectMd5() throws Exception {
    // setup
    setupBucketMetaData(USER_NAME, bucketName);
    FileUtils.forceMkdir(new File(String.format("%s/%s", BUCKET_ROOT, bucketName)));
    String md5 = new String(Base64.encodeBase64(DigestUtils.md5(testData.getBytes())));

    // act
    runCommand(
        String.format(
            "%s put %s %s \"%s\" \"{'content-md5'=>'%s'}\"",
            rightscaleBaseCommandWithGoodUser, bucketName, objectName, testData, md5));

    // assert
    assertResponse(commandExecutor.getOutputLines(), "true");
    File file = new File(String.format("%s/%s/%s", BUCKET_ROOT, bucketName, objectName));
    String readFileToString = FileUtils.readFileToString(file);
    assertEquals(testData, readFileToString);
  }
コード例 #10
0
 public String generateMD5(InputStream fi) throws IOException {
   byte[] buffer = DigestUtils.md5(fi);
   String s = DigestUtils.md5Hex(buffer);
   return s;
 }
コード例 #11
0
 @Override
 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
   Path relativePath = rootPath.relativize(file);
   String downloadURL =
       urlBase + "/" + relativePath.toString().replace("\\", "/").replace(" ", "%20");
   InputStream is = Files.newInputStream(file);
   byte[] hash = DigestUtils.md5(is);
   String md5 = new String(Hex.encodeHex(hash));
   String name = file.getFileName().toString();
   String id;
   name = name.substring(0, name.length() - 4);
   id = name.replace(" ", "");
   String depends = "";
   Boolean required = true;
   Boolean inJar = false;
   Boolean extract = false;
   Boolean inRoot = false;
   Boolean isDefault = true;
   Boolean coreMod = false;
   System.out.println(relativePath.toString());
   if (relativePath.toString().contains(".DS_Store")) {
     return FileVisitResult.CONTINUE;
   }
   if (relativePath.toString().indexOf(sep) >= 0) {
     switch (relativePath.toString().substring(0, relativePath.toString().indexOf(sep))) {
         // Ignore these folders
       case "bin":
       case "lib":
       case "resources":
       case "saves":
       case "screenshots":
       case "stats":
       case "texturepacks":
       case "texturepacks-mp-cache":
         return FileVisitResult.CONTINUE;
         //
       case "instMods":
       case "jar":
         {
           inJar = true;
           break;
         }
       case "coremods":
         {
           coreMod = true;
           break;
         }
       case "config":
         {
           String newPath = relativePath.toString();
           if (sep.equals("\\")) {
             newPath = newPath.replace("\\", "/");
           }
           ConfigFile newConfig = new ConfigFile(downloadURL, newPath, false, md5);
           parent.AddConfig(new ConfigFileWrapper("", newConfig));
           return FileVisitResult.CONTINUE;
         }
       default:
     }
   }
   try {
     ZipFile zf = new ZipFile(file.toFile());
     System.out.println(zf.size() + " entries in file.");
     JdomParser parser = new JdomParser();
     JsonRootNode modInfo =
         parser.parse(new InputStreamReader(zf.getInputStream(zf.getEntry("mcmod.info"))));
     JsonNode subnode;
     if (modInfo.hasElements()) {
       subnode = modInfo.getElements().get(0);
     } else {
       subnode = modInfo.getNode("modlist").getElements().get(0);
     }
     id = subnode.getStringValue("modid");
     name = subnode.getStringValue("name");
     zf.close();
   } catch (NullPointerException e) {
   } catch (ZipException e) {
     System.out.println("Not an archive.");
   } catch (IOException e) {
     e.printStackTrace();
   } catch (InvalidSyntaxException e) {
     e.printStackTrace();
   } finally {
     Module newMod =
         new Module(
             name,
             id,
             downloadURL,
             depends,
             required,
             inJar,
             0,
             true,
             extract,
             inRoot,
             isDefault,
             coreMod,
             md5,
             null,
             "both",
             null);
     parent.AddModule(newMod);
   }
   return FileVisitResult.CONTINUE;
 }