List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex
public static String md5Hex(String data)
From source file:com.rz.action.admin.DriverAction.java
@Validations(requiredStrings = { @RequiredStringValidator(fieldName = "driver.name", message = "????!") }) @InputConfig(resultName = "error") public String update() { Driver persistent = driverService.load(id); persistent.setName(driver.getName()); persistent.setMobile(driver.getMobile()); persistent.setWeixinId(driver.getWeixinId()); if (driver.getCompany() != null && driver.getCompany().getId() != null) { persistent.setCompany(driver.getCompany()); }// w ww . j av a 2 s . c o m persistent.setGrade(driver.getGrade()); persistent.setRating(driver.getRating()); persistent.setGender(driver.getGender()); String drivingYears = this.getRequest().getParameter("drivingYears"); if (drivingYears != null) { persistent.setLicenseDate(DateUtil.dateIncreaseByYear(new Date(), 0 - Integer.valueOf(drivingYears))); } // persistent.setCityId(driver.getCityId()); String passwordMd5 = DigestUtils.md5Hex(driver.getPassword()); persistent.setPassword(passwordMd5); driverService.update(persistent); Admin admin = persistent.getAdmin(); if (admin != null) { if (driver.getPassword() != null && driver.getPassword().length() > 0) { admin.setPassword(driver.getPassword()); } admin.setUsername(driver.getMobile()); adminService.update(admin); } redirectUrl = "driver!list.action"; return SUCCESS; }
From source file:ec.com.espe.arqui.web.LoginBean.java
public void login() { enNuuevoCliente = false;/*from w ww. jav a 2s . c o m*/ //FacesContext context = FacesContext.getCurrentInstance(); RequestContext context = RequestContext.getCurrentInstance(); FacesMessage msg = null; //String direccion="null"; this.empleado = empleadoServicio.buscarEmpleadoPorUsuario(username); if (this.empleado != null && this.empleado.getUsuario().equals(username) && this.empleado.getClave().equals(DigestUtils.md5Hex(password))) { //((HttpServletRequest) context.getExternalContext().getRequest()).getSession().setAttribute("usuario", this.cliente); //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "Bienvenido")); //direccion= "inicio?faces-redirect=true"; loggedIn = true; msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Bienvenid@", username); } else { //FacesContext.getCurrentInstance().addMessage(null, // new FacesMessage(FacesMessage.SEVERITY_WARN, "Error", "Usuario y/o password incorrectos")); //direccion= "index"; loggedIn = false; msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Credenciales no vlidas"); } FacesContext.getCurrentInstance().addMessage(null, msg); context.addCallbackParam("estaLogeado", loggedIn); if (loggedIn) { if (this.empleado.getTipo().equals("A")) { context.addCallbackParam("view", "faces/inicio.xhtml"); } else { context.addCallbackParam("view", "faces/inicio.xhtml"); } } //return direccion; }
From source file:com.blackducksoftware.integration.phonehome.PhoneHomeRequestBodyBuilder.java
public String md5Hash(final String string) throws NoSuchAlgorithmException, UnsupportedEncodingException { final MessageDigest md = MessageDigest.getInstance(MessageDigestAlgorithms.MD5); final byte[] hashedBytes = md.digest(string.getBytes("UTF-8")); return DigestUtils.md5Hex(hashedBytes); }
From source file:com.seajas.search.utilities.spring.security.service.ExtendedUserDetailsService.java
/** * Retrieve the given UserDetails by both username and credentials. The credentials being stored in MD5, we convert it to that before authenticating. * //from ww w.j av a 2s . co m * @param username * @param credentials * @return UserDetails * @throws UsernameNotFoundException * @throws DataAccessException * @throws BadCredentialsException */ public UserDetails getUserDetails(final String username, final String credentials) throws UsernameNotFoundException, DataAccessException, BadCredentialsException { UserDetails userDetails = loadUserByUsername(username); if (userDetails.getPassword().equals(DigestUtils.md5Hex(credentials))) return userDetails; else throw new BadCredentialsException("The given username / password are invalid"); }
From source file:de.wusel.partyplayer.gui.PartyPlayer.java
@Override protected void startup() { statusbar = new LockingStatusbar(this, getMainFrame(), settings); statusbar.addLockingListener(lockingListener); startTime = System.currentTimeMillis(); log.info("Application started @[" + startTime + "]"); player.addListener(playerListener);//from ww w . ja v a 2 s.c om playerModel.addPlaylistListener(playListListener); addExitListener(new ExitListener() { @Override public boolean canExit(EventObject eo) { if (settings.isPasswordValid(null) || unlocked) { return true; } else { final String showInputDialog = JOptionPane.showInputDialog(getMainFrame(), getText("exit.requestPin.label")); return showInputDialog != null && settings.isPasswordValid(DigestUtils.md5Hex(showInputDialog)); } } @Override public void willExit(EventObject eo) { playerModel.exportXML(PathUtil.getLibraryFile()); settings.backup(PathUtil.getSettingsFile()); playerModel.logUserFavorites(); log.info("Application stopped @[" + System.currentTimeMillis() + "] running for [" + (System.currentTimeMillis() - startTime) / 1000 + "]seconds"); } }); FrameView mainView = getMainView(); mainView.setComponent(createMainComponent()); mainView.setStatusBar(statusbar); show(mainView); }
From source file:com.todoroo.astrid.service.abtesting.ABTestInvoker.java
/** * Converts the JSONArray payload into an HTTPEntity suitable for * POSTing./*w w w . ja va2 s.co m*/ * @param payload * @return */ private HttpEntity createPostData(JSONArray payload) throws IOException { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("apikey", API_KEY)); if (payload != null) params.add(new BasicNameValuePair("payload", payload.toString())); StringBuilder sigBuilder = new StringBuilder(); for (NameValuePair entry : params) { if (entry.getValue() == null) continue; String key = entry.getName(); String value = entry.getValue(); sigBuilder.append(key).append(value); } sigBuilder.append(API_SECRET); String signature = DigestUtils.md5Hex(sigBuilder.toString()); params.add(new BasicNameValuePair("sig", signature)); try { return new UrlEncodedFormEntity(params, HTTP.UTF_8); } catch (UnsupportedEncodingException e) { throw new IOException("Unsupported URL encoding"); } }
From source file:com.eviware.loadui.impl.conversion.ReferenceToFileConverter.java
@Override public File convert(Reference source) { if (source.getId().charAt(0) == ':') return new File(source.getId().substring(1)); File target = getOrCreate(source); String hash = source.getId(); synchronized (target) { while (!target.exists() || filesInProgress.contains(hash)) { try { log.debug("waiting for {}", source.getId()); target.wait();//from ww w .j a v a 2s . com } catch (InterruptedException e) { log.debug("got waken up, was waiting for {}", source.getId()); } } FileInputStream fis = null; try { fis = new FileInputStream(target); String md5Hex = DigestUtils.md5Hex(fis); log.debug("target is: {} and is {} bytes with hash " + md5Hex, target, target.length()); } catch (IOException e) { log.error("Exception while verifying hash", e); e.printStackTrace(); } finally { Closeables.closeQuietly(fis); } } return target; }
From source file:net.oauth.example.provider.core.ExoOAuth3LeggedProviderService.java
/** * Generate a fresh request token and secret for a consumer. * @param accessor object will contain token * @throws OAuthException/*from ww w .j av a2s. c om*/ */ public synchronized void generateRequestToken(OAuthAccessor accessor) throws OAuthException { // generate oauth_token and oauth_secret String consumer_key = (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 = consumer_key + System.nanoTime(); String token = DigestUtils.md5Hex(token_data); // for now use md5 of name + current time + token as secret String secret_data = consumer_key + System.nanoTime() + token; String secret = DigestUtils.md5Hex(secret_data); accessor.requestToken = token; accessor.tokenSecret = secret; accessor.accessToken = null; // add to the local cache tokens.put(accessor.requestToken, accessor); System.out.println(tokens.getCacheSize()); }
From source file:com.dominion.salud.mpr.negocio.service.admin.impl.UsuariosServiceImpl.java
@Override public Usuarios saveAndFlush(Usuarios usuarios) { 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())); }//from www . ja va2s.c o m } else { usuarios.setTxtPassword(DigestUtils.md5Hex(usuarios.getTxtPassword())); } return usuariosRepository.saveAndFlush(usuarios); }
From source file:it.univaq.incipict.profilemanager.presentation.AdministrationUserController.java
@RequestMapping(value = "/update", method = { RequestMethod.POST }) public String update(@ModelAttribute User user) { if (isPasswordChanged(user)) { user.setPassword(DigestUtils.md5Hex(user.getPassword())); }/* w w w . j ava 2 s . co m*/ userService.update(user); // change session user information if (new AuthenticationHolder().isAuthenticated(user)) { new AuthenticationHolder().updateUser(user); Role administratorRole = new Role(); administratorRole.setId(Role.ADMINISTRATOR_ROLE_ID); if (!user.getRoles().contains(administratorRole)) { return "redirect:/dashboard"; } } return "redirect:/administration/user/list"; }