Example usage for org.apache.commons.codec.digest DigestUtils md5Hex

List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils md5Hex.

Prototype

public static String md5Hex(String data) 

Source Link

Usage

From source file:com.m3.methodcache.interceptor.AbstractCacheResultInterceptor.java

/**
 * Returns cache key/*from  w ww  .j  a v a  2s . c om*/
 *
 * @param invocation method invocation
 * @param raw        is raw
 * @return cache key
 */
protected String getCacheKey(MethodInvocation invocation, boolean raw) {
    Method invokedMethod = invocation.getMethod();
    String signature = getClassPartOnly(invokedMethod) + "#" + getMethodPartOnly(invokedMethod) + "_$$_";
    String args = getArgsPart(invocation.getArguments()).toString();
    String rawKey = signature + args;
    if (log.isDebugEnabled()) {
        log.debug("Raw key: " + rawKey);
    }
    return raw ? rawKey : DigestUtils.md5Hex(rawKey);
}

From source file:com.sammyun.controller.shop.member.PasswordController.java

/**
 * /*from  www  .j a v  a  2  s .c  o  m*/
 */
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(String currentPassword, String password, HttpServletRequest request,
        RedirectAttributes redirectAttributes) {
    if (StringUtils.isEmpty(password) || StringUtils.isEmpty(currentPassword)) {
        return ERROR_VIEW;
    }
    if (!isValid(Member.class, "password", password)) {
        return ERROR_VIEW;
    }
    Setting setting = SettingUtils.get();
    if (password.length() < setting.getPasswordMinLength()
            || password.length() > setting.getPasswordMaxLength()) {
        return ERROR_VIEW;
    }
    Member member = memberService.getCurrent();
    if (!StringUtils.equals(DigestUtils.md5Hex(currentPassword), member.getPassword())) {
        return ERROR_VIEW;
    }
    member.setPassword(DigestUtils.md5Hex(password));
    memberService.update(member);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:edit.ct";
}

From source file:mx.edu.ittepic.proyectofinal.ejbs.ejbContrasena.java

public String updateUserWithPassword(String userid, String username, String password, String phone,
        String neigborhood, String zipcode, String city, String country, String state, String region,
        String street, String email, String streetnumber, String photo, String cellphone, String companyid,
        String roleid, String gender) {

    Message m = new Message();
    Users r = new Users();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();/*ww  w  .  ja  v a2s. co m*/

    Company com = entity.find(Company.class, Integer.parseInt(companyid));
    Role rol = entity.find(Role.class, Integer.parseInt(roleid));

    try {
        Query q = entity.createNamedQuery("Users.updateUserWithPassword").setParameter("username", username)
                .setParameter("password", password).setParameter("phone", phone)
                .setParameter("neigborhood", neigborhood).setParameter("zipcode", zipcode)
                .setParameter("city", city).setParameter("country", country).setParameter("state", state)
                .setParameter("region", region).setParameter("street", street).setParameter("email", email)
                .setParameter("streetnumber", streetnumber).setParameter("photo", photo)
                .setParameter("cellphone", cellphone).setParameter("companyid", com).setParameter("roleid", rol)
                .setParameter("gender", gender.charAt(0)).setParameter("userid", Integer.parseInt(userid));

        String pass = password;
        String passmd5 = DigestUtils.md5Hex(pass);

        Query a = entity.createNamedQuery("Users.updateUserWithPasswordE").setParameter("username", username)
                .setParameter("password", passmd5).setParameter("phone", phone)
                .setParameter("neigborhood", neigborhood).setParameter("zipcode", zipcode)
                .setParameter("city", city).setParameter("country", country).setParameter("state", state)
                .setParameter("region", region).setParameter("street", street).setParameter("email", email)
                .setParameter("streetnumber", streetnumber).setParameter("photo", photo)
                .setParameter("cellphone", cellphone).setParameter("companyid", com).setParameter("roleid", rol)
                .setParameter("gender", gender.charAt(0)).setParameter("userid", Integer.parseInt(userid));

        if (q.executeUpdate() == 1 && a.executeUpdate() == 1) {
            m.setCode(200);
            m.setMsg("Se actualizo correctamente.");
            m.setDetail("OK");
        } else {
            m.setCode(404);
            m.setMsg("No se realizo la actualizacion");
            m.setDetail("");
        }

    } catch (IllegalStateException e) {
        m.setCode(404);
        m.setMsg("No se realizo la actualizacion");
        m.setDetail(e.toString());
    } catch (TransactionRequiredException e) {
        m.setCode(404);
        m.setMsg("No se realizo la actualizacion");
        m.setDetail(e.toString());
    } catch (QueryTimeoutException e) {
        m.setCode(404);
        m.setMsg("No se realizo la actualizacion");
        m.setDetail(e.toString());
    } catch (PersistenceException e) {
        m.setCode(404);
        m.setMsg("No se realizo la actualizacion");
        m.setDetail(e.toString());
    }
    return gson.toJson(m);
}

From source file:fll.web.admin.ChangePassword.java

@Override
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {
    final DataSource datasource = ApplicationAttributes.getDataSource(application);
    Connection connection = null;
    try {/*www. j  av a2s. c  o m*/
        connection = datasource.getConnection();

        final Collection<String> loginKeys = CookieUtils.findLoginKey(request);
        final String user = Queries.checkValidLogin(connection, loginKeys);

        final String passwordHash = Queries.getHashedPassword(connection, user);
        final String oldPassword = request.getParameter("old_password");
        final String hashedOldPass = DigestUtils.md5Hex(oldPassword);
        if (!ComparisonUtils.safeEquals(passwordHash, hashedOldPass)) {
            session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>Old password is incorrect</p>");
            response.sendRedirect(response.encodeRedirectURL("changePassword.jsp"));
            return;
        }

        final String newPassword = request.getParameter("pass");
        final String newPasswordCheck = request.getParameter("pass_check");
        if (!ComparisonUtils.safeEquals(newPassword, newPasswordCheck)) {
            session.setAttribute(SessionAttributes.MESSAGE, "<p class='error'>New passwords don't match</p>");
            response.sendRedirect(response.encodeRedirectURL("changePassword.jsp"));
            return;
        }

        final String newPasswordHash = DigestUtils.md5Hex(newPassword);

        // invalidate all login keys now that the password has changed
        Queries.changePassword(connection, user, newPasswordHash);
        Queries.removeValidLoginByUser(connection, user);

        session.setAttribute(SessionAttributes.MESSAGE,
                "<p id='success'>Password changed for '" + user + "', you will now need to login again.</p>");
        response.sendRedirect(response.encodeRedirectURL("changePassword.jsp"));

    } catch (final SQLException e) {
        throw new RuntimeException(e);
    } finally {
        SQLFunctions.close(connection);
    }

}

From source file:controllers.UserBean.java

public void setPassword(String password) {
    if (password == null) {
        password = "";
    }//from w  ww  . j  a  va 2  s .c om
    this.password = DigestUtils.md5Hex(password); // Crypt password
}

From source file:com.dhenton9000.filedownloader.CheckFileHash.java

/**
 * Performs a expectedFileHash check on a File.
 *
 * @return//from   ww  w  . j a va 2 s  . c o m
 * @throws IOException
 */
public boolean hasAValidHash() throws IOException {
    if (this.fileToCheck == null) {
        throw new FileNotFoundException("File to check has not been set!");
    }
    if (this.expectedFileHash == null || this.typeOfHash == null) {
        throw new NullPointerException("Hash details have not been set!");
    }
    if (!this.fileToCheck.exists()) {
        throw new FileNotFoundException("File '" + fileToCheck.getCanonicalPath() + "' not found");
    }

    String actualFileHash = "";
    boolean isHashValid = false;

    switch (this.typeOfHash) {
    case MD5:
        actualFileHash = DigestUtils.md5Hex(new FileInputStream(this.fileToCheck));
        if (this.expectedFileHash.equals(actualFileHash)) {
            isHashValid = true;
        }
        break;
    case SHA1:
        actualFileHash = DigestUtils.shaHex(new FileInputStream(this.fileToCheck));
        if (this.expectedFileHash.equals(actualFileHash)) {
            isHashValid = true;
        }
        break;
    }

    LOG.info("Filename = '" + this.fileToCheck.getName() + "'");
    LOG.info("Expected Hash = '" + this.expectedFileHash + "'");
    LOG.info("Actual Hash = '" + actualFileHash + "'");

    return isHashValid;
}

From source file:es.uvigo.ei.sing.gc.view.models.PersonalViewModel.java

@DependsOn({ "oldPassword", "newPassword", "repeatPassword" })
public boolean isPasswordOk() {
    return Validator.isPassword(this.oldPassword)
            && this.user.getPassword().equals(DigestUtils.md5Hex(this.oldPassword))
            && Validator.isPassword(this.newPassword) && this.newPassword.equals(this.repeatPassword);
}

From source file:net.duckling.ddl.service.oauth.impl.OAuthServiceImpl.java

@Override
public void generateAccessToken(OAuthAccessor accessor) {

    // generate oauth_token and oauth_secret
    String consumerKey = (String) accessor.consumer.getProperty("name");
    // generate token and secret based on consumer_key

    // for now use md5 of name + current time as token
    String token_data = consumerKey + System.nanoTime();
    String token = DigestUtils.md5Hex(token_data);

    String oldRequestToken = accessor.requestToken;
    // first remove the accessor from cache
    accessor.requestToken = null;/* w  w w  .j  a v a 2s .co  m*/
    accessor.accessToken = token;

    AccessorPo po;
    if (oldRequestToken != null) {
        po = accessorDAO.getAccessor(oldRequestToken);
        po.copyDateFrom(accessor);
        accessorDAO.updateAccessor(po);
    } else {
        po = new AccessorPo();
        po.copyDateFrom(accessor);
        accessorDAO.createAccessor(po);
    }
}

From source file:com.betel.flowers.service.UsuarioService.java

public Boolean checkPassword(Usuario usuario) {
    Boolean password = Boolean.FALSE;
    Usuario user = this.findByUsername(usuario);
    if (user.getId() != null) {
        String inputPasswordUser = DigestUtils.md5Hex(usuario.getPassword());
        if (user.getPassword().equals(inputPasswordUser)) {
            password = Boolean.TRUE;
        }//from  w  ww .ja  v  a  2 s.c  o  m
    }
    return password;
}

From source file:com.lingxiang2014.controller.shop.PasswordController.java

@RequestMapping(value = "/find", method = RequestMethod.POST)
public @ResponseBody Message find(String captchaId, String captcha, String username, String email) {
    if (!captchaService.isValid(CaptchaType.findPassword, captchaId, captcha)) {
        return Message.error("shop.captcha.invalid");
    }/*from   w ww  .j  a  v a  2s  .  c om*/
    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(email)) {
        return Message.error("shop.common.invalid");
    }
    Member member = memberService.findByUsername(username);
    if (member == null) {
        return Message.error("shop.password.memberNotExist");
    }
    if (!member.getEmail().equalsIgnoreCase(email)) {
        return Message.error("shop.password.invalidEmail");
    }
    Setting setting = SettingUtils.get();
    SafeKey safeKey = new SafeKey();
    safeKey.setValue(UUID.randomUUID().toString() + DigestUtils.md5Hex(RandomStringUtils.randomAlphabetic(30)));
    safeKey.setExpire(setting.getSafeKeyExpiryTime() != 0
            ? DateUtils.addMinutes(new Date(), setting.getSafeKeyExpiryTime())
            : null);
    member.setSafeKey(safeKey);
    memberService.update(member);
    mailService.sendFindPasswordMail(member.getEmail(), member.getUsername(), safeKey);
    return Message.success("shop.password.mailSuccess");
}