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.msds.km.service.Impl.DrivingLicenseRecognitionServcieiImpl.java

/**
 * MD5??//  w  w  w .j av a 2 s. c  o m
 * 
 * @return
 * @throws IOException
 */
protected String getSignature(byte[] b) {
    if (b == null) {
        return null;
    }
    return DigestUtils.md5Hex(b);
}

From source file:com.dominion.salud.mpr.negocio.service.admin.impl.UsuariosServiceImpl.java

@Override
public <S extends Usuarios> List<S> save(Iterable<S> usuarioss) {
    Iterator<S> iterador = usuarioss.iterator();
    while (iterador.hasNext()) {
        Usuarios usuarios = iterador.next();
        if (usuarios.getIdUsuario() != null && usuariosRepository.exists(usuarios.getIdUsuario())) {
            Usuarios existe = findOne(usuarios.getIdUsuario());
            if (!StringUtils.equals(existe.getTxtPassword(), usuarios.getTxtPassword())) {
                usuarios.setTxtPassword(DigestUtils.md5Hex(usuarios.getTxtPassword()));
            }//w  w  w  . j  a  v a  2  s  .  c o  m
        } else {
            usuarios.setTxtPassword(DigestUtils.md5Hex(usuarios.getTxtPassword()));
        }
    }
    return usuariosRepository.save(usuarioss);
}

From source file:com.digitalpebble.stormcrawler.parse.filter.MD5SignatureParseFilter.java

@Override
public void filter(String URL, byte[] content, DocumentFragment doc, ParseResult parse) {
    ParseData parseData = parse.get(URL);
    Metadata metadata = parseData.getMetadata();
    if (copyKeyName != null) {
        String signature = metadata.getFirstValue(key_name);
        if (signature != null) {
            metadata.setValue(copyKeyName, signature);
        }// w  w  w  .  ja v  a 2s .  co  m
    }
    byte[] data = null;
    if (useText) {
        String text = parseData.getText();
        if (StringUtils.isNotBlank(text)) {
            data = text.getBytes(StandardCharsets.UTF_8);
        }
    } else {
        data = content;
    }
    if (data == null) {
        data = URL.getBytes(StandardCharsets.UTF_8);
    }
    String hex = DigestUtils.md5Hex(data);
    metadata.setValue(key_name, hex);
}

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

/**
 * ???//from ww w  .  j a  v a2s .co m
 */
@RequestMapping(value = "/find", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> find(String username, String email) {
    Map<String, Object> data = new HashMap<String, Object>();
    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(email)) {
        data.put("returnCode", 1);
        data.put("returnMessage", SpringUtils.getMessage("shop.common.invalid"));
        return data;
    }
    Member member = memberService.findByUsername(username);
    if (member == null) {
        data.put("returnCode", 1);
        data.put("returnMessage", SpringUtils.getMessage("shop.password.memberNotExist"));
        return data;
    }
    if (!member.getEmail().equalsIgnoreCase(email)) {
        data.put("returnCode", 1);
        data.put("returnMessage", SpringUtils.getMessage("shop.password.invalidEmail"));
        return data;
    }
    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);

    data.put("returnCode", 0);
    data.put("returnMessage", SpringUtils.getMessage("shop.password.sentEmail"));
    return data;
}

From source file:de.shadowhunt.subversion.internal.AbstractHelper.java

private String calculateMd5(final File zip) throws IOException {
    try (final InputStream is = new FileInputStream(zip)) {
        return DigestUtils.md5Hex(is);
    }//  www.java  2s  . co  m
}

From source file:net.shopxx.service.impl.AdminServiceImpl.java

@Transactional(readOnly = true)
@Cacheable(value = "loginToken")
public String getLoginToken() {
    return DigestUtils.md5Hex(UUID.randomUUID() + RandomStringUtils.randomAlphabetic(30));
}

From source file:com.twinsoft.convertigo.engine.admin.services.roles.Add.java

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String[] roles = request.getParameterValues("roles");

    Element root = document.getDocumentElement();
    Element response = document.createElement("response");

    try {// w w  w  . ja  v  a2s . c  om
        if (StringUtils.isBlank(username)) {
            throw new IllegalArgumentException("Blank username not allowed");
        }

        if (StringUtils.isBlank(password)) {
            throw new IllegalArgumentException("Blank password not allowed");
        }

        if (Engine.authenticatedSessionManager.hasUser(username)) {
            throw new IllegalArgumentException("User '" + username + "' already exists");
        }

        Set<Role> set;
        if (roles == null) {
            set = Collections.emptySet();
        } else {
            set = new HashSet<Role>(roles.length);
            for (String role : roles) {
                set.add(Role.valueOf(role));
            }
        }
        Engine.authenticatedSessionManager.setUser(username, DigestUtils.md5Hex(password), set);
        response.setAttribute("state", "success");
        response.setAttribute("message", "User '" + username + "' have been successfully declared!");
    } catch (Exception e) {
        Engine.logAdmin.error("Error during adding the user!\n" + e.getMessage());

        response.setAttribute("state", "error");
        response.setAttribute("message", "Error during adding the user!\n" + e.getMessage());
    }
    root.appendChild(response);
}

From source file:com.openthinks.webscheduler.service.WebSecurityService.java

public Optional<User> validateUser(String userName, String userPass) {
    User user = getUsers().findByName(userName);
    if (user != null && userPass != null) {
        String encryptPass = DigestUtils.md5Hex(userPass);
        if (user.getPass().equals(encryptPass)) {
            User loginUserInfo = user.clone();//fix second login failed issue
            loginUserInfo.setPass(null);
            return Optional.of(loginUserInfo);
        }/* w  w  w  .  jav a2s.  c  o  m*/
    }
    return Optional.empty();
}

From source file:com.dp2345.controller.mall.CartController.java

/**
 * /*from  w  w w.java  2  s .c o  m*/
 */
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody Message add(Long id, Integer quantity, HttpServletRequest request,
        HttpServletResponse response) {
    if (quantity == null || quantity < 1) {
        return ERROR_MESSAGE;
    }
    Product product = productService.find(id);
    if (product == null) {
        return Message.warn("shop.cart.productNotExsit");
    }
    if (!product.getIsMarketable()) {
        return Message.warn("shop.cart.productNotMarketable");
    }
    if (product.getIsGift()) {
        return Message.warn("shop.cart.notForSale");
    }
    // ??
    Cart cart = cartService.getCurrent();
    // ??
    Member member = memberService.getCurrent();
    // 
    if (cart == null) {
        cart = new Cart();
        cart.setKey(UUID.randomUUID().toString() + DigestUtils.md5Hex(RandomStringUtils.randomAlphabetic(30)));
        cart.setMember(member);
        cartService.save(cart);
    }

    // ?????
    if (Cart.MAX_PRODUCT_COUNT != null && cart.getCartItems().size() >= Cart.MAX_PRODUCT_COUNT) {
        return Message.warn("shop.cart.addCountNotAllowed", Cart.MAX_PRODUCT_COUNT);
    }

    //??
    if (cart.contains(product)) {
        CartItem cartItem = cart.getCartItem(product);
        // ????
        if (CartItem.MAX_QUANTITY != null && cartItem.getQuantity() + quantity > CartItem.MAX_QUANTITY) {
            return Message.warn("shop.cart.maxCartItemQuantity", CartItem.MAX_QUANTITY);
        }
        // 
        if (product.getStock() != null && cartItem.getQuantity() + quantity > product.getAvailableStock()) {
            return Message.warn("shop.cart.productLowStock");
        }
        // ?
        cartItem.add(quantity);
        // ??
        cartItemService.update(cartItem);
    } else {
        // ??
        if (CartItem.MAX_QUANTITY != null && quantity > CartItem.MAX_QUANTITY) {
            return Message.warn("shop.cart.maxCartItemQuantity", CartItem.MAX_QUANTITY);
        }
        // 
        if (product.getStock() != null && quantity > product.getAvailableStock()) {
            return Message.warn("shop.cart.productLowStock");
        }
        // 
        CartItem cartItem = new CartItem();
        cartItem.setQuantity(quantity);
        cartItem.setProduct(product);
        cartItem.setCart(cart);
        cartItemService.save(cartItem);
        cart.getCartItems().add(cartItem);
    }

    // ?cookie?
    if (member == null) {
        WebUtils.addCookie(request, response, Cart.ID_COOKIE_NAME, cart.getId().toString(), Cart.TIMEOUT);
        WebUtils.addCookie(request, response, Cart.KEY_COOKIE_NAME, cart.getKey(), Cart.TIMEOUT);
    }
    // ??
    return Message.success("shop.cart.addSuccess", cart.getQuantity(),
            currency(cart.getEffectivePrice(), true, false));
}

From source file:models.JugUser.java

/**
 * Creates a new user. I prefer to generate a random password instead of asking the user to provide
 * its password. Thus I can store it as plain text.
 *
 * @param email     is the user email.//from  www. j a v a2  s. com
 * @param firstName is the first name
 * @param lastName  is the last name
 */
public JugUser(String email, String firstName, String lastName) {
    this.email = email;
    this.firstName = firstName;
    this.lastName = lastName;
    this.password = RandomStringUtils.randomAlphanumeric(8);
    this.creationDate = new Date();
    this.emailConfirmed = false;
    if (email != null) {
        this.gravatarId = DigestUtils.md5Hex(email.trim().toLowerCase());
    }
}