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:es.uvigo.ei.sing.rubioseq.gui.view.models.UserViewModel.java

@Command
public void checkLogin() {
    final Object value = this.em
            .createQuery("SELECT u FROM User u WHERE u.username = '" + this.loginUserName + "'")
            .getSingleResult();//w  w  w  .  j a  v a 2  s .co m
    if (value instanceof User) {
        final User user = (User) value;

        if (user.getPassword().equals(DigestUtils.md5Hex(this.loginPassword))) {
            final Session webSession = Sessions.getCurrent();
            webSession.setAttribute("user", user);
            checkDatastores(user);
        } else {
            Messagebox.show("Incorrect password.", "Invalid login", Messagebox.OK, Messagebox.ERROR);
        }
    } else {
        Messagebox.show("User does not exists.", "Invalid login", Messagebox.OK, Messagebox.ERROR);
    }
}

From source file:net.duckling.ddl.web.controller.BaseController.java

/**
 * ?csrf token ?:"CSRF"+DUCKLING_NAME++IDmd5
 * @param request/*from  w  w  w  .j  a  v  a2 s  .  co m*/
 * @return
 */
protected String getCsrfToken(HttpServletRequest request) {
    String basePath = request.getSession().getServletContext().getRealPath("/");
    VWBContext context = VWBContext.createContext(request, UrlPatterns.PLAIN);
    return DigestUtils
            .md5Hex("CSRF" + Constant.DUCKLING_NAME + Constant.getVersion(basePath) + context.getCurrentUID());
}

From source file:com.demo.db.dao.impl.DriverDaoImpl.java

@Override
public int updateByCell(Driver driver) {
    QueryRunner queryRunner = dbHelper.getRunner();

    try {/*w  w  w.j  av  a  2s  .  c o m*/
        int rows = queryRunner.update(dbHelper.getConnection(),
                "update demo_driver set password=? where cell=?", DigestUtils.md5Hex(driver.getPassword()),
                driver.getCell());
        return rows;
    } catch (SQLException e) {
        LOGGER.error("? ?{}", driver);
        throw new RuntimeException("?", e);
    }
}

From source file:com.chiorichan.util.StringUtil.java

public static String md5(byte[] bytes) {
    return DigestUtils.md5Hex(bytes);
}

From source file:com.comdosoft.financial.manage.service.AgentService.java

@Transactional("transactionManager")
public boolean update(Integer id, Integer types, String name, String cardId, String companyName,
        String businessLicense, String phone, String email, Integer cityId, String address, String username,
        String password, Byte accountType, String cardIdPhotoPath, String licenseNoPicPath) {
    Agent agent = agentMapper.findAgentInfo(id);
    agent.setTypes(types);/*w ww.  j  a  va2  s .  co  m*/
    agent.setName(name);
    agent.setCardId(cardId);
    agent.setCompanyName(companyName);
    agent.setBusinessLicense(businessLicense);
    agent.setPhone(phone);
    agent.setEmail(email);
    agent.setAddress(address);
    agent.setCardIdPhotoPath(cardIdPhotoPath);
    agent.setLicenseNoPicPath(licenseNoPicPath);
    Customer customer = agent.getCustomer();
    if (!customer.getUsername().equals(username)) {
        Customer customer1 = customerMapper.selectByUsername(username);
        if (customer1 == null) {
            customer.setUsername(username);
            customer.setAccountType(accountType);
        } else {
            return false;
        }
    }
    if (password != null && !password.equals("")) {
        String md5Password = DigestUtils.md5Hex(password);
        customer.setPassword(md5Password);
    }
    customer.setCityId(cityId);
    customerMapper.updateByPrimaryKey(customer);
    agentMapper.updateByPrimaryKey(agent);
    return true;
}

From source file:com.napkindrawing.dbversion.InstalledRevision.java

public void assignUpgradeScriptCompiledChecksum() {
    upgradeScriptCompiledChecksum = DigestUtils.md5Hex(upgradeScriptCompiled);
}

From source file:net.shopxx.shiro.realm.AuthenticationRealm.java

/**
 * ???//from w ww. j a  v a  2 s .  co  m
 * 
 * @param token 
 * @return ??
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) {
    AuthenticationToken authenticationToken = (AuthenticationToken) token;
    String username = authenticationToken.getUsername();
    String password = new String(authenticationToken.getPassword());
    String captchaId = authenticationToken.getCaptchaId();
    String captcha = authenticationToken.getCaptcha();
    String ip = authenticationToken.getHost();
    if (!isDevModel && !captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) {
        throw new UnsupportedTokenException();
    }
    if (username != null && password != null) {
        Admin admin = adminService.findByUsername(username);
        if (admin == null) {
            throw new UnknownAccountException();
        }
        if (!admin.getIsEnabled()) {
            throw new DisabledAccountException();
        }
        Setting setting = SettingUtils.get();
        if (admin.getIsLocked()) {
            if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) {
                int loginFailureLockTime = setting.getAccountLockTime();
                if (loginFailureLockTime == 0) {
                    throw new LockedAccountException();
                }
                Date lockedDate = admin.getLockedDate();
                Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime);
                if (new Date().after(unlockDate)) {
                    admin.setLoginFailureCount(0);
                    admin.setIsLocked(false);
                    admin.setLockedDate(null);
                    adminService.update(admin);
                } else {
                    throw new LockedAccountException();
                }
            } else {
                admin.setLoginFailureCount(0);
                admin.setIsLocked(false);
                admin.setLockedDate(null);
                adminService.update(admin);
            }
        }
        if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) {
            int loginFailureCount = admin.getLoginFailureCount() + 1;
            if (loginFailureCount >= setting.getAccountLockCount()) {
                admin.setIsLocked(true);
                admin.setLockedDate(new Date());
            }
            admin.setLoginFailureCount(loginFailureCount);
            adminService.update(admin);
            throw new IncorrectCredentialsException();
        }
        admin.setLoginIp(ip);
        admin.setLoginDate(new Date());
        admin.setLoginFailureCount(0);
        adminService.update(admin);
        return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName());
    }
    throw new UnknownAccountException();
}

From source file:at.stefanproell.ResultSetVerification.ResultSetVerificationAPI.java

/**
 * Calculate md5 hash from input//from   www . j  a  v a 2  s.  c  o m
 *
 * @param inputString
 * @return
 * @throws NoSuchAlgorithmException
 */
public String calculateMD5HashFromString(String inputString) {
    try {
        this.crypto.update(inputString.getBytes("utf8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    String hash = DigestUtils.md5Hex(this.crypto.digest());
    return hash;

}

From source file:br.com.pfood.mb.imp.ProdutoMB.java

public void handleFileUpload(FileUploadEvent event) throws IOException {
    if (listaImagensProduto.size() <= 5) {
        String dir = AppUtil.getDirFilesVendor() + usuarioLogado.getUsuario().getVendedor().getIdVendedor()
                + "/";
        String fileName = event.getFile().getFileName();

        InputStream is = event.getFile().getInputstream();
        String extencao = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
        extencao = extencao.replace("jpeg", "jpg");
        if (!extencao.equalsIgnoreCase("jpg")) {
            messageUtil.addMenssageWarn("Imagens devem ser do tipo JPG");
            return;
        }/*w  w w .j  av a2s .  c  o  m*/
        fileName = DigestUtils.md5Hex(fileName) + "." + extencao;

        try {
            FileOutputStream out = new FileOutputStream(dir + "or/" + fileName);
            int read = 0;
            byte[] bytes = new byte[1024];

            while ((read = is.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }

            out.close();
            out = null;
        } catch (Exception ex) {
            Logger.getLogger(ProdutoMB.class.getName()).log(Level.SEVERE, null, ex);
        }
        is.close();
        is = null;
        BufferedImage imagem = ImageIO.read(ImageIO.createImageInputStream(new File(dir + "or/" + fileName)));

        if (imagem.getWidth() >= 128 || imagem.getHeight() >= 128) {
            ImagemUtil.redimenImagem(dir + "sm/" + fileName, dir + "or/" + fileName, 128, 128, extencao);
        } else {
            ImagemUtil.redimenImagem(dir + "sm/" + fileName, dir + "or/" + fileName, imagem.getWidth(null),
                    imagem.getHeight(null), extencao);
        }

        if (imagem.getWidth() >= 640 || imagem.getHeight() >= 640) {
            ImagemUtil.redimenImagem(dir + "md/" + fileName, dir + "or/" + fileName, 640, 640, extencao);
        } else {
            ImagemUtil.redimenImagem(dir + "md/" + fileName, dir + "or/" + fileName, imagem.getWidth(null),
                    imagem.getHeight(null), extencao);
        }

        Imagem i = new Imagem();
        i.setCodigo(Imagecode.IMG_PRODUTO.getImgCode());
        i.setDescricao(event.getFile().getFileName());
        i.setHash(DigestUtils.md5Hex(event.getFile().getFileName()));
        i.setNomeArquivo(fileName);
        try {
            produtoBO.save(i);
            ImagemProduto imgProd = new ImagemProduto();
            imgProd.setProduto(obj);
            imgProd.setImagem(i);
            imgProd.setSequencia(listaImagensProduto.size() + 1);
            produtoBO.save(imgProd);
            listaImagensProduto.add(imgProd);
        } catch (Exception ex) {
            ex.printStackTrace();
            Logger.getLogger(ProdutoMB.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        messageUtil.addMenssageWarn("Maximo de 6 imagens por produto");
    }

}

From source file:de.wusel.partyplayer.gui.LockingStatusbar.java

public LockingStatusbar(Application application, final JFrame mainFrame, final Settings settings) {
    this.application = application;
    this.settings = settings;
    this.application.getContext().getTaskMonitor().addPropertyChangeListener(listener);
    statusLabel = new JLabel("Ready");
    fileReaderProgressBar = new JProgressBar(0, 100);

    pinCodeInputField = new JPasswordField();
    PromptSupport.setPrompt("pin-code", pinCodeInputField);
    PromptSupport.setForeground(Color.GRAY, pinCodeInputField);

    pinCodeInputField.addMouseListener(new MouseAdapter() {

        @Override//from   www. j  a v a2s  .  c  om
        public void mouseClicked(MouseEvent e) {
            if (!pinCodeInputField.isEnabled()) {
                ChangePasswordDialog dialog = new ChangePasswordDialog(mainFrame, settings);
                dialog.setVisible(true);
                if (dialog.getStatus() == DialogStatus.CONFIRMED) {
                    settings.setNewPassword(dialog.getPassDigest());
                    settings.backup(PathUtil.getSettingsFile());
                }
            }
        }
    });
    pinCodeInputField.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean unlocked = settings
                    .isPasswordValid(DigestUtils.md5Hex(new String(pinCodeInputField.getPassword())));
            if (unlocked) {
                pinCodeInputField.transferFocus();
                unlock();
            }
            pinCodeInputField.setText(null);
        }
    });

    lockButton = new JToggleButton();
    lockButton.setIcon(getIcon("lock"));
    lockButton.setSelectedIcon(getIcon("lock_open"));
    lockButton.setEnabled(false);
    lockButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            lock();
        }
    });

    this.settingsButton = new JButton(getIcon("cog_edit"));
    this.settingsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showSettings();
        }
    });
    add(statusLabel, new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL));
    add(fileReaderProgressBar, new JXStatusBar.Constraint(200));
    add(pinCodeInputField, new JXStatusBar.Constraint(100));
    add(lockButton, new JXStatusBar.Constraint());
    add(settingsButton, new JXStatusBar.Constraint());
    this.mainFrame = mainFrame;
}